I am connecting an outdated application (written in COBOL) with our .NET new ones using channels. The idea is simple: an outdated program (my ERP menu) writes some parameters to the stream, the .NET application reads it through the Console.In stream and starts a new stream that opens the requested screen. Here is a snippet from the .NET side of how this idea works:
<STAThread(), LoaderOptimization(LoaderOptimization.MultiDomain)> Shared Sub Main() If Environment.GetCommandLineArgs(1) = "PIPE" While True Dim pipeParam as String Try pipeParam = Console.In.ReadLine() Catch e as Exception Exit Sub End Try ' Deal with parameters here If pipeParam = "END" Dim newThread as New Threading.Thread(Sub() ' Create a new AppDomain and Loads the menu option, generally a Winforms form. End Sub) newThread.Start() End If End While End If End Sub
Everything worked perfectly and easily ... until today. I deployed this solution in my client environment (Windows Server 2003), and it happened that none of the requested threads were executed, except when the called process (COBOL) was terminated (i.e. Console.In was forcibly closed) . From now on, all requested winforms will begin to display and behave as expected.
Digging through this strange behavior in logs, I found out that threads usually execute until the IDictionary.ContainsKey() statement (or some other method that requires the execution of native code) is executed. At that moment, the thread froze / slept.
If I restrict the creation of a stream to, say, three, it happens that each created stream hangs to the third, that is, when Console.In.ReadLine no longer executed.
What should I do? Any tips?
Additional info: The closest direction I have found so far was Hans Passan's answer in this question: Interface freezes in a multithreaded C # application (.NET SystemEvents appears in my debbuger thread list, but I could not solve my problem with the proposed solution )
UPDATED NEWS
I could solve this problem while waiting for a subflow to complete the Form loading. This Done signal is passed through AppDomain.SetData() and AppDomain.GetData() . Anyway, after creating the form, the sub-stream no longer hangs when the main one goes to Console.ReadLine . Although the problem is resolved, I am intrigued by this. I am trying to reproduce this in a "simple" case.
Some additional information
- Starting point .exe compiled into 32-bit. All other libraries are "AnyCpu". The problem arises both on 32-bit (my client) and 64-bit (my developments) machines (both Windows Server 2003).
- Updated
Sub Main() attributes in the above snippet. - I tried to put
Console.ReadLine in the workflow. Failed to solve (see the figure below). - The COBOL application will not be dependent because it runs in a separate OS process. The pipe is my IPC approach. The COBOL application in this case records only the parameters and does not wait for an answer.
- The stack trace is in the image below (the
PRX001235 stream deserializes the xml configuration file before connecting to the database and before loading the form efficiently - in this case, it still seems to be in managed code - sometimes the PRX001235 stream will hang in its own code when trying to connect to the database data):
