C# Browse for Folder dialog hangs if shown with Owner


i'm using folder browser component library assembly (a plugin app).  library assembly being called application not single apartment threaded nor can make one.  unfortunately, seems that this component requires sta as throws exception if called other threading model.  reproduced, , documented.

so doing creating new singleapartmentthreaded thread , calling showdialog() that.  works.  but of course shows dialog modelessly.  not cool.  should simple enough, if pass in iwin32window reference, show child of window, right?  heh...not so.

however, if nativewindow of top-level window of process i'm running in, have verified spy correct handle, when call showdialog() using parent window handle hangs.  have reproduced using own form in test.  whenever pass in owning window, hangs.

i assume because cross-thread?  dialog being shown in 1 thread, parent window in thread?

if there other workaround can show modally?  can't show in main thread, because not sta?!?

of course write own dialog, that seems incredible waste of time?

thanks in advance this...



actually figured out once stepped away bit , started thinking going on.

since had create separate stathread in order component work, had have main thread wait until dialog done showing return calling application selected folder.  had done thread.join().  native calling thread had blocked running message pump win32 process.  since caller wasn't code, couldn't sure.

so after starting thread had replace join() call loop runs while dialog being shown (in other thread) , repeatedly calls application.doevents().

then worked charm!

 



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'