Groups | Blog | Home
all groups > dotnet clr > may 2004 >

dotnet clr : Deadlock in C#, CreateProcess, MFC


Werner B. Strydom
5/27/2004 11:32:49 PM
Hi,

I'm having some trouble launching an MFC application from a .NET
application. In a Winforms application [written in C#], I use the Process
class to start an MFC application. The MFC application creates, automates
and destroys several COM objects (including Microsoft Word) in a background
thread. Often we will get that the C# application causes the MFC application
deadlock, while the C# application waits for the process to terminate. If at
that time, I kill the C# application, the MFC application continues.

It seems to be deadlocking in WaitForSingleObject. Using a C++ managed
class, I used CreateProcess inside a managed class to spawn the MFC
application; and that deadlocks too in when WaitForSingleObject is called.
Again killing the .NET application is the only way to get the MFC
application to continue.

The only way I managed to fix it, is to use C++ managed code to call the MFC
code directly; that is without spawning off any process. However, if the MFC
application misbehaves, it does sabotage the managed code.

Do you perhaps have an idea why waiting for a MFC process to quit in C# or
C++ could cause that MFC process to deadlock? This was done in the .NET
framework 1.0, and MFC 7.0.

Thanks
Werner


Jared Parsons [MSFT]
6/1/2004 10:39:05 AM
Are you using LoadLibrary() or running code in DllMain() in the C++
application? If so check out this blog by CBrumme. It's rather lengthy but
it may be related to the problem you are having.

http://blogs.msdn.com/cbrumme/archive/2004/02/21/77595.aspx

--
Jared Parson [MSFT]
jaredpar@online.microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

[quoted text, click to view]

AddThis Social Bookmark Button