Is it safe to open each C#.Net WinForm in a separate thread?
Posted on 2008-06-11
The real problem I am trying to solve is that I would like all modal dialog boxes to be modal only to their parent form. In C#.Net, however, all modal dialog boxes (using ShowDialog) are modal to the entire thread. There are, therefore two possible solutions to this problem: 1) mimic ShowDialog() by using Show() and disabling the parent a different way, or 2) open each WinForm in a separate thread so that any modal dialog boxes only lock that one form.
Option #1 was explored in question #23378010, but I'd like to explore the other option (one thread per form) with this question. It will take some work to make our application thread-safe, so I'd like to know first if this is even a viable option.
Initial testing of this option seems to work ok, except that I will occasionally get a 'System.OutOfMemoryException Error creating window handle at System.Windows.Forms.NativeWindow.CreateHandle' exception when I try to open several windows in rapid succession ( I do not get the same exception if I open the same number of windows slowly).
We are using C# and .Net 1.1
Does anyone have experience with opening different forms in different threads?