I have an application which has an asynchronous operation built into it that loops over a large number of items and performs lengthy calculations on each item, as this occurs certain conditions will cause the application to pop up a modal dialog for user input. Interestingly, I noticed while running this today that in one application instance the modal dialogs somehow got the wrong parent form- rather than providing a modal block to my application the dialogs had taken a Digsby chat window as their parent.

The Digsby window that they became children of popped up around the same time as the first dialog was created (possibly the exact same time) and it would seem that they threads somehow crossed one another because the Digsby window became completely blocked until the async operation completed. I do not know how this is possible considering how per-process threading works, but it certainly did happen. What would cause such a bug? The application is C# .NET 3.5 with Windows Forms running on Windows XP, by the way.

The reason this is the answer is that the docs for the no-argument ShowDialog() say: "...the currently active window is made the owner of the dialog box. If you want to specify a specific owner, use the other version of this method." See msdn.microsoft.com/en-us/library/c7ykbedk.aspx
–
Andrew WattMar 27 '09 at 6:41