|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Deadlock in XmlSerializer when using RedirectStandardInputI have encountered a situation where a thread (say, thread-1) blocks for 10 minutes in the XmlSerializer constructor. This occurs when another thread (say, thread-2) is blocked in a call to Console.ReadLine and the process was created using System.Diagnostics.Process with RedirectStandardInput = true. In this situation, not only does thread-1 block for 10 min in the XmlSerializer constructor, but so will hang indefinitely when creating a COM object. The problem started occuring after migrating our application to .NET v2.0. I found a forum post where some other developers have run into the exact same problem. Please see this link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=188895&SiteID=1 (it also includes a reproducible testcase) Background We need to run multiple instances of an console application (it runs until told to stop). Since we need to run more than one process on a single machine it did not make sense to make the application a windows service. Instead we developed a windows services that spawns these (child) application processes. Using the System.Diagnostics.Process class we can not only spawn the process, but interact with it via stdin and stdout. (Not so nice) Workarounds It appears that the XmlSerializer hangs in the call to csc.exe (you can see this child process using ProcessExplorer). I can get around this problem by sgen'ing the assembly which eliminates the need for spawning csc.exe at runtime. However, this doesn't fix the problem with creating COM objects. Another workaround i've seen (see forum post mentioned above) is to not call Console.ReadLine(). However, I need this call in order to process interactive commandline input. Also note the call to ReadLine is on an MTA thread, so there should not be any STA "pumping" issues. ------------ Is anyone aware of a decent workaround to this issue (or a fix available ..NET 2.0)? I seems that this problem greatly limits the usefulness of stdin redirection. |
|||||||||||||||||||||||