Agarici
asked on
deadlock when using waitOne in a STA thread
Hi,
I have the problem described bellow with the calls to WaitHandle.WaitOne
causing re-entrancy on main GUI thread (STA) of a .NET application and I
would like to find out:
  - did anybody else run into the same problem?
  - is it a known issue? is there a fix for it?
  - is there a workaround for it?
  - if no fix/workaround I would like to find out the complete list of
messages that are being handled (dispatched by ole32.dll OLE/COM message
pump) when doing WaitOne on a STA thread.
The problem is:
I have 2 (or more) calls pending to execute on the main gui thread (I am
actually doing Invoke on some control)
the first call, at some point does WaitHandle.WaitOne.
at this point, if a Windows message comes to the app (like
WM_POPUPSYSTEMMENU - 0x0313 ) triggered by a right-click on the task bar
icon of the app the following happens:
  - the app processes this message
  - the app starts processing other pending messages - like my second
invoke
  - at this point my app is deadlocked, because it is not supposed to
enter the second call before finishing processing the first one.
  - also at this point the entire system is not behaving properly - for
example I cannot bring up any window by clicking on the taskbar icon
important note: if I would not do right click on the taskbar icon of my app,
and just let it work in background, everything would be ok.
After investigating this issue for a while, I found that WaitOne is not
actually a blocking call when called from an STA thread.
The only reference  I found related to this matter in  MSDN pages is here:
http://msdn.microsoft.com/en-us/library/74169f59.aspx .
Quoting from that page:
 "WaitHandle..::.WaitOne,Wa itHandle.. ::.WaitAny , WaitHandle..::.WaitAll,
Monitor..::.Enter, Monitor..::.TryEnter, Thread..::.Join,
GC..::.WaitForPendingFinal izers, and so on are all responsive to
Thread..::.Interrupt and to Thread..::.Abort. Also, if your thread is in a
single-threaded apartment, all these managed blocking operations will
correctly pump messages in your apartment while your thread is blocked."
If the apartment state is STA this function actually creates a message loop
that is processing some events (for now I have been able to identify 2 of
them (WM_POPUPSYSTEMMENU and WM_ACTIVATEAPP). Â The problem is that these
messages triggers processing of other messages in the queue (like the
registered messages used for invoke in .NET ).
I have attached a simplified application to demonstrate the issue. In this
app I have created a thread from where I am calling multiple times the same
function which is suppose to execute on the GUI thread.
I have put some console prints to show that it is executing another invoke
on the main thread even if it is supposed to stay in the wait.
Another thing, in my app the calls to some functions are not supposed to
re-enter (and we are protecting them with the waitOnes) but if I modified
the sample app (attached to this mail) to have a non-blocking re-entrancy ,
I noticed if I right click on the taskbar icon while the first call is in
waitOne, all the other calls will be executed before the first call ends -
this is actually easy to explain since the other calls are not processed by
the app message loop but they are processed by the message loop created by
the WaitOne. however I don't think this should be the normal behavior - that
is: when I invoke 3 calls on some thread, the order of execution should be
the order of the invokes.
waiting forward for your replies
A.
I have the problem described bellow with the calls to WaitHandle.WaitOne
causing re-entrancy on main GUI thread (STA) of a .NET application and I
would like to find out:
  - did anybody else run into the same problem?
  - is it a known issue? is there a fix for it?
  - is there a workaround for it?
  - if no fix/workaround I would like to find out the complete list of
messages that are being handled (dispatched by ole32.dll OLE/COM message
pump) when doing WaitOne on a STA thread.
The problem is:
I have 2 (or more) calls pending to execute on the main gui thread (I am
actually doing Invoke on some control)
the first call, at some point does WaitHandle.WaitOne.
at this point, if a Windows message comes to the app (like
WM_POPUPSYSTEMMENU - 0x0313 ) triggered by a right-click on the task bar
icon of the app the following happens:
  - the app processes this message
  - the app starts processing other pending messages - like my second
invoke
  - at this point my app is deadlocked, because it is not supposed to
enter the second call before finishing processing the first one.
  - also at this point the entire system is not behaving properly - for
example I cannot bring up any window by clicking on the taskbar icon
important note: if I would not do right click on the taskbar icon of my app,
and just let it work in background, everything would be ok.
After investigating this issue for a while, I found that WaitOne is not
actually a blocking call when called from an STA thread.
The only reference  I found related to this matter in  MSDN pages is here:
http://msdn.microsoft.com/en-us/library/74169f59.aspx .
Quoting from that page:
 "WaitHandle..::.WaitOne,Wa
Monitor..::.Enter, Monitor..::.TryEnter, Thread..::.Join,
GC..::.WaitForPendingFinal
Thread..::.Interrupt and to Thread..::.Abort. Also, if your thread is in a
single-threaded apartment, all these managed blocking operations will
correctly pump messages in your apartment while your thread is blocked."
If the apartment state is STA this function actually creates a message loop
that is processing some events (for now I have been able to identify 2 of
them (WM_POPUPSYSTEMMENU and WM_ACTIVATEAPP). Â The problem is that these
messages triggers processing of other messages in the queue (like the
registered messages used for invoke in .NET ).
I have attached a simplified application to demonstrate the issue. In this
app I have created a thread from where I am calling multiple times the same
function which is suppose to execute on the GUI thread.
I have put some console prints to show that it is executing another invoke
on the main thread even if it is supposed to stay in the wait.
Another thing, in my app the calls to some functions are not supposed to
re-enter (and we are protecting them with the waitOnes) but if I modified
the sample app (attached to this mail) to have a non-blocking re-entrancy ,
I noticed if I right click on the taskbar icon while the first call is in
waitOne, all the other calls will be executed before the first call ends -
this is actually easy to explain since the other calls are not processed by
the app message loop but they are processed by the message loop created by
the WaitOne. however I don't think this should be the normal behavior - that
is: when I invoke 3 calls on some thread, the order of execution should be
the order of the invokes.
waiting forward for your replies
A.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace DeadLockWaitOne
{
public partial class Form1 : Form
{
#region Designer
private Button button1;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(86, 31);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.ResumeLayout(false);
}
#endregion Designer
#region My Code
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(delegate()
{
test(1);
test(2);
test(3);
test(4);
test(5);
}
);
t.IsBackground = true;
t.Start();
}
private delegate void TestDelegate(int callNo);
private static int enterCount = 0;
private void test(int callNo)
{
Console.WriteLine("Entering... {0}", callNo);
if ( this.InvokeRequired )
{
BeginInvoke(new TestDelegate(test), callNo);
return;
}
int enterCountValue = Interlocked.Increment(ref enterCount);
Console.WriteLine("Entered {0} - {1} time", callNo, enterCountValue);
System.Threading.AutoResetEvent ev = new System.Threading.AutoResetEvent(false);
// if you comment out the next line you will see that the order of execution changes - it becomes 2,3,4,5,1
// i've put the if here to simulate the situation i have in my app.
if ( enterCountValue == 1 )
{
System.Threading.Thread t = new System.Threading.Thread(delegate()
{
Thread.Sleep(10000);
ev.Set();
});
t.IsBackground = true;
t.Start();
}
ev.WaitOne();
Console.WriteLine("Doing something meaningfull for call #{0}", callNo);
Console.WriteLine("Exited {0} - {1} time", callNo, enterCountValue);
enterCountValue = Interlocked.Decrement(ref enterCount);
}
#endregion My Code
}
public class Program
{
[STAThread]
public static void Main(string[] args)
{
System.Windows.Forms.Application.Run(new Form1());
}
}
}
sorry -- ignore my last post
place the definition of the thread as a class member instead of a local-- each time you enter that method you are creating a new ev.-- that may be why it isn't waiting
ASKER
no difference - in may app it is like you say - the code i posted is quickly created to reproduce the same problem i have in my app (which is much larger and cannot post it here)
the thing is it processes the invokes normally as long as no other message comes to the main window. if a message comes - like the one generated by the right click on the taskbar - it processes the next event even thow the previous invoke did not finish. i discovered that's because of the message loop created by the waitOne.
what is even interesting, if the reentrancy is not blocking, the order of executing the 5 invokes will not be 1,2,3,4,5 - it will change to be 2,3,4,5,1
in my posted test code you can achieve this by commenting the 'if ( enterCountValue == 1 )' line. in this case you will see the output in the console beeig:
Doing something meaningfull for call #2
Doing something meaningfull for call #3
Doing something meaningfull for call #4
Doing something meaningfull for call #5
Doing something meaningfull for call #1
Regards,
A.
the thing is it processes the invokes normally as long as no other message comes to the main window. if a message comes - like the one generated by the right click on the taskbar - it processes the next event even thow the previous invoke did not finish. i discovered that's because of the message loop created by the waitOne.
what is even interesting, if the reentrancy is not blocking, the order of executing the 5 invokes will not be 1,2,3,4,5 - it will change to be 2,3,4,5,1
in my posted test code you can achieve this by commenting the 'if ( enterCountValue == 1 )' line. in this case you will see the output in the console beeig:
Doing something meaningfull for call #2
Doing something meaningfull for call #3
Doing something meaningfull for call #4
Doing something meaningfull for call #5
Doing something meaningfull for call #1
Regards,
A.
you could always use a mutex instead of relying on the threads wait one i tested and it gave 12345.
class member mutex -- waitone at the beginning of the method and the releasemutex at the end.
class member mutex -- waitone at the beginning of the method and the releasemutex at the end.
ASKER
it gave 12345 if you don't interfere. if while in the first wait you right-click on the taskbar icon, it will change like i said.
that is because only when you right click on the taskbar the system message comes to the app and generates the processing of the second pending invoke
changing the code like you said is not an option - i did not test it yet, but it's imposible for me to go changing all the code in our app like that. the are thousands of places where we rely on the WaitOne. we cannot workaround this issue everywhere.
that is because only when you right click on the taskbar the system message comes to the app and generates the processing of the second pending invoke
changing the code like you said is not an option - i did not test it yet, but it's imposible for me to go changing all the code in our app like that. the are thousands of places where we rely on the WaitOne. we cannot workaround this issue everywhere.
i doing some reading of examples -- it looks like you have to set again to  signal that the processing is done-- i tried to follow your steps to recreate the issue after i added the second ev.Set(); i wasn't able to recreate -- maybe you can -- but it is worth a try.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace DeadLockWaitOne
{
public partial class Form1 : Form
{
#region Designer
private Button button1;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(86, 31);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.ResumeLayout(false);
}
#endregion Designer
#region My Code
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(delegate()
{
test(1);
test(2);
test(3);
test(4);
test(5);
}
);
t.IsBackground = true;
t.Start();
}
private delegate void TestDelegate(int callNo);
private static int enterCount = 0;
private void test(int callNo)
{
Console.WriteLine("Entering... {0}", callNo);
if ( this.InvokeRequired )
{
BeginInvoke(new TestDelegate(test), callNo);
return;
}
int enterCountValue = Interlocked.Increment(ref enterCount);
Console.WriteLine("Entered {0} - {1} time", callNo, enterCountValue);
System.Threading.AutoResetEvent ev = new System.Threading.AutoResetEvent(false);
// if you comment out the next line you will see that the order of execution changes - it becomes 2,3,4,5,1
// i've put the if here to simulate the situation i have in my app.
if ( enterCountValue == 1 )
{
System.Threading.Thread t = new System.Threading.Thread(delegate()
{
Thread.Sleep(10000);
ev.Set();
});
t.IsBackground = true;
t.Start();
}
ev.WaitOne();
Console.WriteLine("Doing something meaningfull for call #{0}", callNo);
Console.WriteLine("Exited {0} - {1} time", callNo, enterCountValue);
enterCountValue = Interlocked.Decrement(ref enterCount);
ev.Set(); //<----------------------------------------------------ADDED HERE
}
#endregion My Code
}
public class Program
{
[STAThread]
public static void Main(string[] args)
{
System.Windows.Forms.Application.Run(new Form1());
}
}
}
I'll go out on a limb and say that link about WaitOne yielding to the mesage pump is either wrong or doesn't apply in this situation. Â I built your code with a 60 second delay instead of 10 and watched it in the debugger. Â It works exactly as I would expect. Â The button click creates a thread using a multicast delegate. Â Each call to test from that thread runs and does the invoke, queueing up the request on the message pump. Â The first invoke happening on the main thread goes into the 60 second wait, and when it finishes the 60 seconds it completes and the second call is pulled from the pump. Â Etc., for the remaining calls. Â I could see that any external events, such as a button click could certainly happen in the middle of the 5 calls and mess things up. Â Does this sound right and if so can you clarify your problem/question?
I see my last couple lines weren't clear. Â Other events can get put in the queue in the middle of the worker threads adding their test calls to the queue, but these events won't interrupt the Wait call and in your example they won't cause reentrant calls on your test method.
ASKER
hi.
First, i'm sorry if my post is so long - i cannot express everything in just a few words.
mastoo, they are beeing processed by the message pump of WaitOne. when i simply let the app run without any intervention, i get the folowing output:
Entering... 1
Entering... 2
Entering... 3
Entering... 4
Entering... 5
Entering... 1
Entered 1 - 1 time
Doing something meaningfull for call #1
Exited 1 - 1 time
Entering... 2
Entered 2 - 1 time
Doing something meaningfull for call #2
Exited 2 - 1 time
Entering... 3
Entered 3 - 1 time
Doing something meaningfull for call #3
Exited 3 - 1 time
Entering... 4
Entered 4 - 1 time
Doing something meaningfull for call #4
Exited 4 - 1 time
Entering... 5
Entered 5 - 1 time
Doing something meaningfull for call #5
Exited 5 - 1 time
if while waiting in the first invoke i right click on the taskbar icon of the app i get this (please notice the order the invokes get executed - the order of messages 'Doing something meaningfull for call #X'):
Entering... 1
Entering... 2
Entering... 3
Entering... 4
Entering... 5
Entering... 1
Entered 1 - 1 time
Entering... 2
Entered 2 - 2 time
Doing something meaningfull for call #2
Exited 2 - 2 time
Entering... 3
Entered 3 - 2 time
Doing something meaningfull for call #3
Exited 3 - 2 time
Entering... 4
Entered 4 - 2 time
Doing something meaningfull for call #4
Exited 4 - 2 time
Entering... 5
Entered 5 - 2 time
Doing something meaningfull for call #5
Exited 5 - 2 time
Doing something meaningfull for call #1
Exited 1 - 1 time
also notice that when i right click on the taskbar icon while the STA thread is in the wait one, the seccond invoke starts executing before the first has finished:
......
Entering... 1
Entered 1 - 1 time
Entering... 2
Entered 2 - 2 time
Doing something meaningfull for call #2
Exited 2 - 2 time
......
if i stop in the debugger at this point i see this stack (i've marked with '>>>' the 2 calls to Form1.test on the stack - notice how the second one starts from the waitOne):
      [In a sleep, wait, or join]     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne(long timeout, bool exitContext) + 0x2e bytes     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne(int millisecondsTimeout, bool exitContext) + 0x23 bytes     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne() + 0xa bytes     Â
>>>>DeadLockWaitOne.exe!De adLockWait One.Form1. test(int callNo = 2) Line 92 + 0xb bytes      C#
      mscorlib.dll!System.Delega te.Dynamic InvokeImpl (object[] args) + 0x5a bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac kDo(System .Windows.F orms.Contr ol.ThreadM ethodEntry tme) + 0x9d bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac kHelper(ob ject obj) + 0x6b bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .runTryCod e(object userData) + 0x43 bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .RunIntern al(System. Threading. ExecutionC ontext executionContext, System.Threading.ContextCa llback callback, object state) + 0xa7 bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .Run(Syste m.Threadin g.Executio nContext executionContext, System.Threading.ContextCa llback callback, object state) + 0x92 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac k(System.W indows.For ms.Control .ThreadMet hodEntry tme) + 0x90 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac ks() + 0xb3 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x800 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Scrollable Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x45 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. ContainerC ontrol.Wnd Proc(ref System.Windows.Forms.Messa ge m) + 0x13 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Form.WndPr oc(ref System.Windows.Forms.Messa ge m) + 0x2b6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.On Message(re f System.Windows.Forms.Messa ge m) + 0xd bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0xd6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. NativeWind ow.Debugga bleCallbac k(System.I ntPtr hWnd, int msg = 49961, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes     Â
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi nProc@20()  + 0x28 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. NativeWind ow.DefWndP roc(ref System.Windows.Forms.Messa ge m = {System.Windows.Forms.Mess age}) + 0x94 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Form.DefWn dProc(ref System.Windows.Forms.Messa ge m) + 0x87 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x87a bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Scrollable Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x45 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. ContainerC ontrol.Wnd Proc(ref System.Windows.Forms.Messa ge m) + 0x13 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Form.WndPr oc(ref System.Windows.Forms.Messa ge m) + 0x2b6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.On Message(re f System.Windows.Forms.Messa ge m) + 0xd bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0xd6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. NativeWind ow.Debugga bleCallbac k(System.I ntPtr hWnd, int msg = 787, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes     Â
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi nProc@20()  + 0x28 bytes     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne(long timeout, bool exitContext) + 0x2e bytes     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne(int millisecondsTimeout, bool exitContext) + 0x23 bytes     Â
      mscorlib.dll!System.Thread ing.WaitHa ndle.WaitO ne() + 0xa bytes     Â
>>>>DeadLockWaitOne.exe!De adLockWait One.Form1. test(int callNo = 1) Line 92 + 0xb bytes      C#
      mscorlib.dll!System.Delega te.Dynamic InvokeImpl (object[] args) + 0x5a bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac kDo(System .Windows.F orms.Contr ol.ThreadM ethodEntry tme) + 0x9d bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac kHelper(ob ject obj) + 0x6b bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .runTryCod e(object userData) + 0x43 bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .RunIntern al(System. Threading. ExecutionC ontext executionContext, System.Threading.ContextCa llback callback, object state) + 0xa7 bytes     Â
      mscorlib.dll!System.Thread ing.Execut ionContext .Run(Syste m.Threadin g.Executio nContext executionContext, System.Threading.ContextCa llback callback, object state) + 0x92 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac k(System.W indows.For ms.Control .ThreadMet hodEntry tme) + 0x90 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.In vokeMarsha ledCallbac ks() + 0xb3 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x800 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Scrollable Control.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0x45 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. ContainerC ontrol.Wnd Proc(ref System.Windows.Forms.Messa ge m) + 0x13 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Form.WndPr oc(ref System.Windows.Forms.Messa ge m) + 0x2b6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.On Message(re f System.Windows.Forms.Messa ge m) + 0xd bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Control.Co ntrolNativ eWindow.Wn dProc(ref System.Windows.Forms.Messa ge m) + 0xd6 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. NativeWind ow.Debugga bleCallbac k(System.I ntPtr hWnd, int msg = 49961, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes     Â
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi nProc@20()  + 0x28 bytes     Â
      user32.dll!_UserCallWinPro cCheckWow@ 32()  + 0xb7 bytes     Â
      user32.dll!_DispatchMessag eWorker@8( )  + 0xdc bytes     Â
      user32.dll!_DispatchMessag eW@4()  + 0xf bytes     Â
      [Managed to Native Transition]     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Applicatio n.Componen tManager.S ystem.Wind ows.Forms. UnsafeNati veMethods. IMsoCompon entManager .FPushMess ageLoop(in t dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2ea bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Applicatio n.ThreadCo ntext.RunM essageLoop Inner(int reason = -1, System.Windows.Forms.Appli cationCont ext context = {System.Windows.Forms.Appl icationCon text}) + 0x17d bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Applicatio n.ThreadCo ntext.RunM essageLoop (int reason, System.Windows.Forms.Appli cationCont ext context) + 0x53 bytes     Â
      System.Windows.Forms.dll!S ystem.Wind ows.Forms. Applicatio n.Run(Syst em.Windows .Forms.For m mainForm) + 0x2e bytes     Â
      DeadLockWaitOne.exe!DeadLo ckWaitOne. Program.Ma in(string[ ] args = {Dimensions:[0]}) Line 108 + 0x1a bytes      C#
      mscoree.dll!__CorExeMain@0 ()  + 0x34 bytes     Â
      kernel32.dll!_BaseProcessS tart@4()  + 0x23 bytes     Â
now, if i look into the unmanaged stack to see why it has processed something else while doing waitOne i see the stack bellow. sorry it's so long. notice how after each WaitOne a meesage loop is started and also notice the message that is processed by this meesage loop while in WaitOne. i've also marked with >>>Â the lines with the calls to Form1.test
OS Thread Id: 0x144c (5196)
Current frame: _KiFastSystemCallRet@0
ChildEBP RetAddr  Caller,Callee
0012c250 7c90df2c _NtWaitForMultipleObjects@ 20+0xc
0012c254 7c809574 _WaitForMultipleObjectsEx@ 20+0x12c, calling _NtWaitForMultipleObjects@ 20
0012c280 7e4193e9 _NtUserPeekMessage@20+0xc
0012c284 7e4193a8 __PeekMessage@24+0x74, calling _NtUserPeekMessage@20
0012c2ac 7e419402 _PeekMessageW@20+0xbc, calling __PeekMessage@24
0012c2d8 7755b2bc ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z+0x30 , calling _PeekMessageW@20
0012c2f0 7e4195f9 _RealMsgWaitForMultipleObj ectsEx@20+ 0x13e, calling _WaitForMultipleObjectsEx@ 20
0012c31c 7752f0b8 ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z+0xa1 , calling __SEH_epilog
0012c320 7752f0f0 ?PeekRPCAndDDEMessage@CCli ModalLoop@ @AAEHXZ+0x 30, calling ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z
0012c34c 7752ebd6 ?BlockFn@CCliModalLoop@@QA EJPAPAXKPA K@Z+0x80, calling _MsgWaitForMultipleObjects Ex@20
0012c374 77557237 _CoWaitForMultipleHandles@ 20+0xcf, calling ?BlockFn@CCliModalLoop@@QA EJPAPAXKPA K@Z
0012c3e8 79f27b88 ?NT5WaitRoutine@@YGKHKHPAP AXH@Z+0x51 , calling _CoWaitForMultipleHandles@ 20
0012c400 79f17565 ?GetFinalApartment@Thread@ @QAE?AW4Ap artmentSta te@1@XZ+0x 8d, calling __EH_epilog3
0012c408 79f27acf ?MsgWaitHelper@@YGKHPAPAXH KH@Z+0xa5, calling ?NT5WaitRoutine@@YGKHKHPAP AXH@Z
0012c45c 79f17565 ?GetFinalApartment@Thread@ @QAE?AW4Ap artmentSta te@1@XZ+0x 8d, calling __EH_epilog3
0012c474 79f27a33 ?DoAppropriateAptStateWait @Thread@@A AEKHPAPAXH KW4WaitMod e@@@Z+0x28 , calling ?MsgWaitHelper@@YGKHPAPAXH KH@Z
0012c494 79f17493 ?DoAppropriateWaitWorker@T hread@@AAE KHPAPAXHKW 4WaitMode@ @@Z+0x144, calling ?DoAppropriateAptStateWait @Thread@@A AEKHPAPAXH KW4WaitMod e@@@Z
0012c518 79f1732f ?DoAppropriateWait@Thread@ @QAEKHPAPA XHKW4WaitM ode@@PAUPe ndingSync@ @@Z+0x40, calling ?DoAppropriateWaitWorker@T hread@@AAE KHPAPAXHKW 4WaitMode@ @@Z
0012c550 79ef5723 ?AcquireSafeHandle@@YGXPAP AVSafeHand le@@@Z+0x3 5, calling __EH_epilog3
0012c568 7a07b49c ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z+0x14e , calling ?DoAppropriateWait@Thread@ @QAEKHPAPA XHKW4WaitM ode@@PAUPe ndingSync@ @@Z
0012c5c4 7a07b2dd ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z+0x21, calling @LazyMachStateCaptureState @4
0012c628 7a080550 ?Start@ThreadNative@@SIXPA VThreadBas eObject@@P AVObject@@ PAW4StackC rawlMark@@ @Z+0x1f, calling @LazyMachStateCaptureState @4
0012c66c 793d424e (MethodDesc 0x7924ad60 +0x2e System.Threading.WaitHandl e.WaitOne( Int64, Boolean)), calling ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z
0012c684 793d4193 (MethodDesc 0x7924ad48 +0x23 System.Threading.WaitHandl e.WaitOne( Int32, Boolean)), calling (MethodDesc 0x7924ad60 +0 System.Threading.WaitHandl e.WaitOne( Int64, Boolean))
0012c698 793d420e (MethodDesc 0x7924ad58 +0xa System.Threading.WaitHandl e.WaitOne( ))
>>>>0012c6a0 012305e7 (MethodDesc 0x925928 +0x1cf DeadLockWaitOne.Form1.test (Int32))
0012c6c0 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr ol+Control NativeWind ow.WndProc (System.Wi ndows.Form s.Message ByRef)), calling 0093704e
0012c6d0 7b08b889 (MethodDesc 0x7b4a7d70 +0xb9 System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr, Int32, IntPtr, IntPtr)), calling  (JitHelp: CORINFO_HELP_GETSHARED_NON GCSTATIC_B ASE)
0012c6f0 79e7c2ca ?SkipExactlyOne@SigParser@ @QAEJXZ+0x 20, calling ?CorSigEatCustomModifiersA ndUncompre ssElementT ype@@YGJPA PBEKPAKPAW 4CorElemen tType@@@Z
0012c720 79e88f63 _CallDescrWorker@20+0x33
0012c730 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012c7b0 79e88e31 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x19 c, calling _CallDescrWorkerWithHandle r@24
0012c7e0 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x 38, calling _memcpy
0012c7ec 79e88db3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xaf , calling ?addition@?$ClrSafeInt@I@@ SG_NIIAAI@ Z
0012c7f8 79e88dc3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xbb , calling __alloca_probe_16
0012c85c 79e74c1c ?Alloc@@YGPAVObject@@IHH@Z +0x60
0012c874 79f18839 ?JIT_MonReliableEnter@@YIX PAVObject@ @PA_N@Z+0x 25, calling @LazyMachStateCaptureState @4
0012c878 79e74ebd ?LazyInit@HelperMethodFram e@@IAEXPAX PAULazyMac hState@@@Z +0x17, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012c890 79e8a1af ??0HelperMethodFrame_1OBJ@ @QAE@PAXPA ULazyMachS tate@@IPAP AVObject@@ @Z+0x14, calling ??0HelperMethodFrame@@QAE@ PAXPAULazy MachState@ @I@Z
0012c8ac 79e88d3b ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x1f , calling __alloca_probe_16
0012c8f0 79e88d19 ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z+0x20, calling ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z
0012c908 79e88cf6 ?Call@MethodDescCallSite@@ QAEXPB_K@Z +0x18, calling ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z
0012c91c 7a11ae16 ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z+ 0x43f, calling ?Call@MethodDescCallSite@@ QAEXPB_K@Z
0012c938 7a11ac68 ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z+ 0x28e, calling __alloca_probe_16
0012c9b0 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z
0012caac 79e74c1c ?Alloc@@YGPAVObject@@IHH@Z +0x60
0012cac4 79f18839 ?JIT_MonReliableEnter@@YIX PAVObject@ @PA_N@Z+0x 25, calling @LazyMachStateCaptureState @4
0012cac8 79e74ebd ?LazyInit@HelperMethodFram e@@IAEXPAX PAULazyMac hState@@@Z +0x17, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012cae0 79e8a1af ??0HelperMethodFrame_1OBJ@ @QAE@PAXPA ULazyMachS tate@@IPAP AVObject@@ @Z+0x14, calling ??0HelperMethodFrame@@QAE@ PAXPAULazy MachState@ @I@Z
0012cb04 7a11b0fa ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z+0x bd, calling ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z
0012cb60 7a11b05e ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z+0x 24, calling @LazyMachStateCaptureState @4
0012cbc4 793cf629 (MethodDesc 0x79248640 +0x49 System.RuntimeMethodHandle .InvokeMet hodFast(Sy stem.Objec t, System.Object[], System.Signature, System.Reflection.MethodAt tributes, System.RuntimeTypeHandle)) , calling ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z
0012cc10 794012bf (MethodDesc 0x79242888 +0x167 System.Reflection.RuntimeM ethodInfo. Invoke(Sys tem.Object , System.Reflection.BindingF lags, System.Reflection.Binder, System.Object[], System.Globalization.Cultu reInfo, Boolean)), calling (MethodDesc 0x79248640 +0 System.RuntimeMethodHandle .InvokeMet hodFast(Sy stem.Objec t, System.Object[], System.Signature, System.Reflection.MethodAt tributes, System.RuntimeTypeHandle))
0012cc48 793ac0fa (MethodDesc 0x7923bbd8 +0x5a System.Delegate.DynamicInv okeImpl(Sy stem.Objec t[])), calling (MethodDesc 0x79242888 +0 System.Reflection.RuntimeM ethodInfo. Invoke(Sys tem.Object , System.Reflection.BindingF lags, System.Reflection.Binder, System.Object[], System.Globalization.Cultu reInfo, Boolean))
0012cc70 7b06ec1d (MethodDesc 0x7b5a5f80 +0x9d System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackDo(T hreadMetho dEntry))
0012cc74 79362186 (MethodDesc 0x7924b598 +0x3e System.Threading.Synchroni zationCont ext.SetSyn chronizati onContext( System.Thr eading.Syn chronizati onContext) ), calling (MethodDesc 0x7913f578 +0 System.Threading.Synchroni zationCont ext.SetSyn chronizati onContext( System.Thr eading.Syn chronizati onContext, System.Threading.Synchroni zationCont ext))
0012cc94 7b06eca7 (MethodDesc 0x7b5a5f78 +0x6b System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackHelp er(System. Object)), calling (MethodDesc 0x7b5a5f80 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackDo(T hreadMetho dEntry))
0012ccc0 793685af (MethodDesc 0x7913f3e0 +0x43 System.Threading.Execution Context.ru nTryCode(S ystem.Obje ct))
0012ccd0 79e88f63 _CallDescrWorker@20+0x33
0012cce0 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012cd60 79e88e31 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x19 c, calling _CallDescrWorkerWithHandle r@24
0012cd90 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x 38, calling _memcpy
0012cd9c 79e88db3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xaf , calling ?addition@?$ClrSafeInt@I@@ SG_NIIAAI@ Z
0012cda8 79e88dc3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xbb , calling __alloca_probe_16
0012ce0c 79e8a69e ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 79d, calling @__security_check_cookie@4
0012ce24 79f293b7 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 x260, calling __EH_epilog3_GS
0012ce28 79f29143 ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z+0x3 8b, calling ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z
0012ce5c 79e88d3b ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x1f , calling __alloca_probe_16
0012cea0 79e88d19 ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z+0x20, calling ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z
0012ceb8 79e88cf6 ?Call@MethodDescCallSite@@ QAEXPB_K@Z +0x18, calling ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z
0012cecc 79ef80d3 ?ExecuteCodeWithGuaranteed CleanupHel per@@YGXPA UECWGC_GC@ @@Z+0xb2, calling ?Call@MethodDescCallSite@@ QAEXPB_K@Z
0012cf94 79e88805 ?SizeOf@SigPointer@@QBEIPA VModule@@P BVSigTypeC ontext@@@Z +0x106, calling __EH_epilog3
0012cf98 79e816f7 ?GetReturnTypeSize@MetaSig @@QAEIXZ+0 x17, calling ?SizeOf@SigPointer@@QBEIPA VModule@@P BVSigTypeC ontext@@@Z
0012cfa0 79e88888 ?CalculateHasFPReturn@Meta Sig@@QAEXX Z+0x8, calling ?GetReturnTypeNormalized@M etaSig@@QB E?AW4CorEl ementType@ @XZ
0012cfa8 79e88a0d ?ForceSigWalk@MetaSig@@QAE XH@Z+0x19d , calling ?CalculateHasFPReturn@Meta Sig@@QAEXX Z
0012d040 79e8a69e ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 79d, calling @__security_check_cookie@4
0012d058 79f293b7 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 x260, calling __EH_epilog3_GS
0012d05c 79f29143 ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z+0x3 8b, calling ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z
0012d098 79ef7fde ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z+0 xf9, calling ?ExecuteCodeWithGuaranteed CleanupHel per@@YGXPA UECWGC_GC@ @@Z
0012d0e0 79ef7f1e ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z+0 x28, calling @LazyMachStateCaptureState @4
0012d148 793684fb (MethodDesc 0x7913f3d8 +0xa7 System.Threading.Execution Context.Ru nInternal( System.Thr eading.Exe cutionCont ext, System.Threading.ContextCa llback, System.Object)), calling ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z
0012d160 793683ee (MethodDesc 0x7913f3d0 +0x92 System.Threading.Execution Context.Ru n(System.T hreading.E xecutionCo ntext, System.Threading.ContextCa llback, System.Object)), calling (MethodDesc 0x7913f3d8 +0 System.Threading.Execution Context.Ru nInternal( System.Thr eading.Exe cutionCont ext, System.Threading.ContextCa llback, System.Object))
0012d178 7b06ed78 (MethodDesc 0x7b4a6450 +0x90 System.Windows.Forms.Contr ol.InvokeM arshaledCa llback(Thr eadMethodE ntry)), calling (MethodDesc 0x7913f3d0 +0 System.Threading.Execution Context.Ru n(System.T hreading.E xecutionCo ntext, System.Threading.ContextCa llback, System.Object))
0012d194 7b06ea6b (MethodDesc 0x7b5a5f88 +0xb3 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbacks()) , calling (MethodDesc 0x7b4a6450 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llback(Thr eadMethodE ntry))
0012d1cc 7b072f30 (MethodDesc 0x7b5a5a50 +0x800 System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef)), calling (MethodDesc 0x7b5a5f88 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbacks())
0012d230 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef)), calling (MethodDesc 0x7b5a5a50 +0 System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012d238 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef)), calling (MethodDesc 0x7b5a5588 +0 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012d23c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form. WndProc(Sy stem.Windo ws.Forms.M essage ByRef)), calling (MethodDesc 0x7b4a5910 +0 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef))
0012d24c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr ol+Control NativeWind ow.OnMessa ge(System. Windows.Fo rms.Messag e ByRef))
0012d250 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr ol+Control NativeWind ow.WndProc (System.Wi ndows.Form s.Message ByRef)), calling 0093704e
0012d264 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr, Int32, IntPtr, IntPtr))
0012d28c 7a4a6956 (MethodDesc 0x7a7ffbb8 +0x26 System.ComponentModel.Even tHandlerLi st.get_Ite m(System.O bject)), calling (MethodDesc 0x7a7ffbe0 +0 System.ComponentModel.Even tHandlerLi st.Find(Sy stem.Objec t))
0012d2a4 79e88f63 _CallDescrWorker@20+0x33
0012d2b4 7b05f80e (MethodDesc 0x7b4a6478 +0x32 System.Windows.Forms.Contr ol.NotifyI nvalidate( System.Dra wing.Recta ngle))
0012d2c0 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012d340 79f2905b ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z+0x55, calling _CallDescrWorkerWithHandle r@24
0012d360 79f29369 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 x1e5, calling ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z
0012d3c8 79f29249 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 xc3, calling __alloca_probe_16
0012d404 7b0814c3 (MethodDesc 0x7b5ab7c0 +0x2b System.Windows.Forms.Butto n.WndProc( System.Win dows.Forms .Message ByRef)), calling (MethodDesc 0x7b5aba60 +0 System.Windows.Forms.Butto nBase.WndP roc(System .Windows.F orms.Messa ge ByRef))
0012d40c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr ol+Control NativeWind ow.OnMessa ge(System. Windows.Fo rms.Messag e ByRef))
0012d410 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr ol+Control NativeWind ow.WndProc (System.Wi ndows.Form s.Message ByRef)), calling 0093704e
0012d464 79f29143 ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z+0x3 8b, calling ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z
0012d498 7c949a41 _RtlAllocateHeapSlowly@12+ 0xd7c, calling _RtlFillMemoryUlong@12
0012d4a0 7c91925d _RtlAllocateHeapSlowly@12+ 0xdc1, calling _RtlpGetExtraStuffPointer@ 4
0012d4a4 7c9192ef _RtlAllocateHeapSlowly@12+ 0x113b, calling __SEH_epilog
0012d4f0 79f75cc2 ?RareDisablePreemptiveGC@T hread@@QAE XXZ+0x3c6, calling _RtlRestoreLastWin32Error@ 4
0012d528 79fdfe26 _StubRareDisableTHROWWorke r@8+0x5d, calling ?HandleThreadAbort@Thread@ @QAEXH@Z
0012d52c 79fdfe35 _StubRareDisableTHROWWorke r@8+0x6c, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012d53c 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z
0012d56c 7e418734 _InternalCallWinProc@20+0x 28
0012d58c 7e418734 _InternalCallWinProc@20+0x 28
0012d5b8 7e418816 _UserCallWinProcCheckWow@3 2+0x150, calling _InternalCallWinProc@20
0012d608 7e42b372 _DispatchHookW@16+0x31
0012d620 7e428ea0 _DispatchClientMessage@20+ 0xa3, calling _UserCallWinProcCheckWow@3 2
0012d65c 7e42b326 _CallHookWithSEH@16+0x44, calling __SEH_epilog
0012d674 7e428eec ___fnDWORD@4+0x24
0012d6c0 7e4194be _NtUserMessageCall@28+0xc
0012d6f0 79fdfe35 _StubRareDisableTHROWWorke r@8+0x6c, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012d700 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z
0012d714 7e428dd9 _RealDefWindowProcW@16+0x4 7, calling _RealDefWindowProcWorker@2 0
0012d730 7e428d77 _DefWindowProcW@16+0x72, calling _RealDefWindowProcW@16
0012d778 7e418734 _InternalCallWinProc@20+0x 28
0012d7a4 7e418816 _UserCallWinProcCheckWow@3 2+0x150, calling _InternalCallWinProc@20
0012d7f4 79e8e1cf ?HandleThreadAbort@Thread@ @QAEXH@Z+0 xa1, calling __EH_epilog3
0012d80c 7e42a013 _CallWindowProcAorW@24+0x9 8, calling _UserCallWinProcCheckWow@3 2
0012d83c 7e42a039 _CallWindowProcW@20+0x1b, calling _CallWindowProcAorW@24
0012d85c 7b07a7d4 (MethodDesc 0x7b4a7d78 +0x94 System.Windows.Forms.Nativ eWindow.De fWndProc(S ystem.Wind ows.Forms. Message ByRef)), calling _CallWindowProcW@20
0012d888 7b07a7d4 (MethodDesc 0x7b4a7d78 +0x94 System.Windows.Forms.Nativ eWindow.De fWndProc(S ystem.Wind ows.Forms. Message ByRef)), calling _CallWindowProcW@20
0012d894 79e8a67b ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 84, calling ?Collapse@StackingAllocato r@@QAEXPAX @Z
0012d8b4 7b05ed83 (MethodDesc 0x7b4a56b0 +0x87 System.Windows.Forms.Form. DefWndProc (System.Wi ndows.Form s.Message ByRef)), calling 7b64f510
0012d8fc 7b072faa (MethodDesc 0x7b5a5a50 +0x87a System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012d960 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef)), calling (MethodDesc 0x7b5a5a50 +0 System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012d968 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef)), calling (MethodDesc 0x7b5a5588 +0 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012d96c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form. WndProc(Sy stem.Windo ws.Forms.M essage ByRef)), calling (MethodDesc 0x7b4a5910 +0 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef))
0012d97c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr ol+Control NativeWind ow.OnMessa ge(System. Windows.Fo rms.Messag e ByRef))
0012d980 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr ol+Control NativeWind ow.WndProc (System.Wi ndows.Form s.Message ByRef)), calling 0093704e
0012d994 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr, Int32, IntPtr, IntPtr))
0012d9d4 79e88f63 _CallDescrWorker@20+0x33
0012d9f0 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012da58 7c802600 _WaitForSingleObjectEx@12+ 0xd8, calling __SEH_epilog
0012da70 79f2905b ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z+0x55, calling _CallDescrWorkerWithHandle r@24
0012da90 79f29369 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 x1e5, calling ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z
0012dafc 79f29249 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 xc3, calling __alloca_probe_16
0012db98 79f29143 ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z+0x3 8b, calling ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z
0012dbc4 7c90da0c _NtReleaseMutant@8+0xc
0012dbc8 7c8024c7 _ReleaseMutex@4+0x10, calling _NtReleaseMutant@8
0012dbd8 7475577a ?Leave@CTimList@@QAEXXZ+0x 1c, calling _ReleaseMutex@4
0012dbe0 74755d2a ?GetDWORD@CTimList@@AAEKKW 4TIEnum@@@ Z+0x7f, calling __SEH_epilog
0012dc24 79f75cc2 ?RareDisablePreemptiveGC@T hread@@QAE XXZ+0x3c6, calling _RtlRestoreLastWin32Error@ 4
0012dc5c 79fdfe26 _StubRareDisableTHROWWorke r@8+0x5d, calling ?HandleThreadAbort@Thread@ @QAEXH@Z
0012dc60 79fdfe35 _StubRareDisableTHROWWorke r@8+0x6c, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012dc70 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z
0012dca0 7e418734 _InternalCallWinProc@20+0x 28
0012dcc0 7e418734 _InternalCallWinProc@20+0x 28
0012dcec 7e418816 _UserCallWinProcCheckWow@3 2+0x150, calling _InternalCallWinProc@20
0012dd54 7e428ea0 _DispatchClientMessage@20+ 0xa3, calling _UserCallWinProcCheckWow@3 2
0012dd84 7e42b317 _CallHookWithSEH@16+0x21
0012dda8 7e428eec ___fnDWORD@4+0x24
0012ddc0 7e4278d0 ___fnHkINLPMSG@4+0x25, calling _CallHookWithSEH@16
0012ddf4 7e4193e9 _NtUserPeekMessage@20+0xc
0012ddf8 7e4193a8 __PeekMessage@24+0x74, calling _NtUserPeekMessage@20
0012de20 7e419402 _PeekMessageW@20+0xbc, calling __PeekMessage@24
0012de4c 7755b2bc ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z+0x30 , calling _PeekMessageW@20
0012de94 7752f0f0 ?PeekRPCAndDDEMessage@CCli ModalLoop@ @AAEHXZ+0x 30, calling ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z
0012dec8 7755b2bc ?MyPeekMessage@CCliModalLo op@@QAEHPA UtagMSG@@P AUHWND__@@ IIG@Z+0x30 , calling _PeekMessageW@20
0012ded4 7752f1ef ?FindMessage@CCliModalLoop @@AAEHK@Z+ 0x2d, calling ?PeekRPCAndDDEMessage@CCli ModalLoop@ @AAEHXZ
0012dee0 7e4195f9 _RealMsgWaitForMultipleObj ectsEx@20+ 0x13e, calling _WaitForMultipleObjectsEx@ 20
0012deec 7e4184ce _NtUserCallNoParam@4+0xc
0012def0 7e4184ba _NtUserCallOneParam@8+0xc
0012def4 7e42ae7a _RealGetQueueStatus@4+0x26 , calling _NtUserCallOneParam@8
0012df04 7752f28f ?HandleWakeForMsg@CCliModa lLoop@@AAE XXZ+0x3b, calling ?FindMessage@CCliModalLoop @@AAEHK@Z
0012df50 7752f23e ?BlockFn@CCliModalLoop@@QA EJPAPAXKPA K@Z+0x8b, calling ?HandleWakeForMsg@CCliModa lLoop@@AAE XXZ
0012df64 77557237 _CoWaitForMultipleHandles@ 20+0xcf, calling ?BlockFn@CCliModalLoop@@QA EJPAPAXKPA K@Z
0012dfd8 79f27b88 ?NT5WaitRoutine@@YGKHKHPAP AXH@Z+0x51 , calling _CoWaitForMultipleHandles@ 20
0012dff0 79f17565 ?GetFinalApartment@Thread@ @QAE?AW4Ap artmentSta te@1@XZ+0x 8d, calling __EH_epilog3
0012dff8 79f27acf ?MsgWaitHelper@@YGKHPAPAXH KH@Z+0xa5, calling ?NT5WaitRoutine@@YGKHKHPAP AXH@Z
0012e04c 79f17565 ?GetFinalApartment@Thread@ @QAE?AW4Ap artmentSta te@1@XZ+0x 8d, calling __EH_epilog3
0012e064 79f27a33 ?DoAppropriateAptStateWait @Thread@@A AEKHPAPAXH KW4WaitMod e@@@Z+0x28 , calling ?MsgWaitHelper@@YGKHPAPAXH KH@Z
0012e084 79f17493 ?DoAppropriateWaitWorker@T hread@@AAE KHPAPAXHKW 4WaitMode@ @@Z+0x144, calling ?DoAppropriateAptStateWait @Thread@@A AEKHPAPAXH KW4WaitMod e@@@Z
0012e108 79f1732f ?DoAppropriateWait@Thread@ @QAEKHPAPA XHKW4WaitM ode@@PAUPe ndingSync@ @@Z+0x40, calling ?DoAppropriateWaitWorker@T hread@@AAE KHPAPAXHKW 4WaitMode@ @@Z
0012e140 79ef5723 ?AcquireSafeHandle@@YGXPAP AVSafeHand le@@@Z+0x3 5, calling __EH_epilog3
0012e158 7a07b49c ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z+0x14e , calling ?DoAppropriateWait@Thread@ @QAEKHPAPA XHKW4WaitM ode@@PAUPe ndingSync@ @@Z
0012e1b4 7a07b2dd ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z+0x21, calling @LazyMachStateCaptureState @4
0012e218 7a080550 ?Start@ThreadNative@@SIXPA VThreadBas eObject@@P AVObject@@ PAW4StackC rawlMark@@ @Z+0x1f, calling @LazyMachStateCaptureState @4
0012e25c 793d424e (MethodDesc 0x7924ad60 +0x2e System.Threading.WaitHandl e.WaitOne( Int64, Boolean)), calling ?CorWaitOneNative@WaitHand leNative@@ SIHPAVSafe Handle@@H_ N1@Z
0012e274 793d4193 (MethodDesc 0x7924ad48 +0x23 System.Threading.WaitHandl e.WaitOne( Int32, Boolean)), calling (MethodDesc 0x7924ad60 +0 System.Threading.WaitHandl e.WaitOne( Int64, Boolean))
0012e288 793d420e (MethodDesc 0x7924ad58 +0xa System.Threading.WaitHandl e.WaitOne( ))
>>>>Â 0012e290 012305e7 (MethodDesc 0x925928 +0x1cf DeadLockWaitOne.Form1.test (Int32))
0012e2d4 79e7bbb1 _PreStubWorker@4+0x138, calling __EH_epilog3
0012e2d8 00351f3e 00351f3e, calling _PreStubWorker@4
0012e310 79e88f63 _CallDescrWorker@20+0x33
0012e318 7c949a41 _RtlAllocateHeapSlowly@12+ 0xd7c, calling _RtlFillMemoryUlong@12
0012e320 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012e3a0 79e88e31 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x19 c, calling _CallDescrWorkerWithHandle r@24
0012e3d0 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x 38, calling _memcpy
0012e3dc 79e88db3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xaf , calling ?addition@?$ClrSafeInt@I@@ SG_NIIAAI@ Z
0012e3e8 79e88dc3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xbb , calling __alloca_probe_16
0012e464 79e74753 ?Leave@CrstBase@@AAEXXZ+0x 96, calling __EH_epilog3
0012e468 79e74ebd ?LazyInit@HelperMethodFram e@@IAEXPAX PAULazyMac hState@@@Z +0x17, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012e480 79e8a1af ??0HelperMethodFrame_1OBJ@ @QAE@PAXPA ULazyMachS tate@@IPAP AVObject@@ @Z+0x14, calling ??0HelperMethodFrame@@QAE@ PAXPAULazy MachState@ @I@Z
0012e49c 79e88d3b ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x1f , calling __alloca_probe_16
0012e4e0 79e88d19 ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z+0x20, calling ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z
0012e4f8 79e88cf6 ?Call@MethodDescCallSite@@ QAEXPB_K@Z +0x18, calling ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z
0012e50c 7a11ae16 ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z+ 0x43f, calling ?Call@MethodDescCallSite@@ QAEXPB_K@Z
0012e528 7a11ac68 ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z+ 0x28e, calling __alloca_probe_16
0012e5c4 79e7d329 ?GetTypeHandleThrowing@Sig Pointer@@Q BE?AVTypeH andle@@PAV Module@@PB VSigTypeCo ntext@@W4L oadTypesFl ag@ClassLo ader@@W4Cl assLoadLev el@@HPBVSu bstitution @@0@Z+0xe9 7, calling __EH_epilog3_GS
0012e5c8 79eec9b8 ?GetLastTypeHandleThrowing @MetaSig@@ QBE?AVType Handle@@W4 LoadTypesF lag@ClassL oader@@W4C lassLoadLe vel@@H@Z+0 x21, calling ?GetTypeHandleThrowing@Sig Pointer@@Q BE?AVTypeH andle@@PAV Module@@PB VSigTypeCo ntext@@W4L oadTypesFl ag@ClassLo ader@@W4Cl assLoadLev el@@HPBVSu bstitution @@0@Z
0012e6b4 79e74753 ?Leave@CrstBase@@AAEXXZ+0x 96, calling __EH_epilog3
0012e6b8 79e74ebd ?LazyInit@HelperMethodFram e@@IAEXPAX PAULazyMac hState@@@Z +0x17, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012e6d0 79e8a1af ??0HelperMethodFrame_1OBJ@ @QAE@PAXPA ULazyMachS tate@@IPAP AVObject@@ @Z+0x14, calling ??0HelperMethodFrame@@QAE@ PAXPAULazy MachState@ @I@Z
0012e6f4 7a11b0fa ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z+0x bd, calling ?InvokeImpl@@YGPAVObject@@ PAVMethodD esc@@PAV1@ PAVPtrArra y@@PAUSign atureNativ e@@KVTypeH andle@@@Z
0012e750 7a11b05e ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z+0x 24, calling @LazyMachStateCaptureState @4
0012e7b4 793cf629 (MethodDesc 0x79248640 +0x49 System.RuntimeMethodHandle .InvokeMet hodFast(Sy stem.Objec t, System.Object[], System.Signature, System.Reflection.MethodAt tributes, System.RuntimeTypeHandle)) , calling ?InvokeMethodFast@RuntimeM ethodHandl e@@SIPAVOb ject@@PAPA VMethodDes c@@PAV2@PA XKPAUSigna tureNative @@PAVPtrAr ray@@@Z
0012e800 794012bf (MethodDesc 0x79242888 +0x167 System.Reflection.RuntimeM ethodInfo. Invoke(Sys tem.Object , System.Reflection.BindingF lags, System.Reflection.Binder, System.Object[], System.Globalization.Cultu reInfo, Boolean)), calling (MethodDesc 0x79248640 +0 System.RuntimeMethodHandle .InvokeMet hodFast(Sy stem.Objec t, System.Object[], System.Signature, System.Reflection.MethodAt tributes, System.RuntimeTypeHandle))
0012e838 793ac0fa (MethodDesc 0x7923bbd8 +0x5a System.Delegate.DynamicInv okeImpl(Sy stem.Objec t[])), calling (MethodDesc 0x79242888 +0 System.Reflection.RuntimeM ethodInfo. Invoke(Sys tem.Object , System.Reflection.BindingF lags, System.Reflection.Binder, System.Object[], System.Globalization.Cultu reInfo, Boolean))
0012e860 7b06ec1d (MethodDesc 0x7b5a5f80 +0x9d System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackDo(T hreadMetho dEntry))
0012e864 79362186 (MethodDesc 0x7924b598 +0x3e System.Threading.Synchroni zationCont ext.SetSyn chronizati onContext( System.Thr eading.Syn chronizati onContext) ), calling (MethodDesc 0x7913f578 +0 System.Threading.Synchroni zationCont ext.SetSyn chronizati onContext( System.Thr eading.Syn chronizati onContext, System.Threading.Synchroni zationCont ext))
0012e884 7b06eca7 (MethodDesc 0x7b5a5f78 +0x6b System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackHelp er(System. Object)), calling (MethodDesc 0x7b5a5f80 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbackDo(T hreadMetho dEntry))
0012e8b0 793685af (MethodDesc 0x7913f3e0 +0x43 System.Threading.Execution Context.ru nTryCode(S ystem.Obje ct))
0012e8c0 79e88f63 _CallDescrWorker@20+0x33
0012e8d0 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012e950 79e88e31 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x19 c, calling _CallDescrWorkerWithHandle r@24
0012e980 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x 38, calling _memcpy
0012e98c 79e88db3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xaf , calling ?addition@?$ClrSafeInt@I@@ SG_NIIAAI@ Z
0012e998 79e88dc3 ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0xbb , calling __alloca_probe_16
0012e9f8 79e8a67b ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 84, calling ?Collapse@StackingAllocato r@@QAEXPAX @Z
0012ea0c 79e8a69e ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 79d, calling @__security_check_cookie@4
0012ea10 7c80262a _WaitForSingleObjectEx@12+ 0xe5, calling _RtlDeactivateActivationCo ntextUnsaf eFast@4
0012ea4c 79e88d3b ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z+0x1f , calling __alloca_probe_16
0012ea90 79e88d19 ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z+0x20, calling ?CallDescr@MethodDesc@@AAE _KPBEPAVMe taSig@@PB_ KHH@Z
0012eaa8 79e88cf6 ?Call@MethodDescCallSite@@ QAEXPB_K@Z +0x18, calling ?CallTargetWorker@MethodDe sc@@AAE_KP BEPAVMetaS ig@@PB_KH@ Z
0012eabc 79ef80d3 ?ExecuteCodeWithGuaranteed CleanupHel per@@YGXPA UECWGC_GC@ @@Z+0xb2, calling ?Call@MethodDescCallSite@@ QAEXPB_K@Z
0012eb84 79e88805 ?SizeOf@SigPointer@@QBEIPA VModule@@P BVSigTypeC ontext@@@Z +0x106, calling __EH_epilog3
0012eb88 79e816f7 ?GetReturnTypeSize@MetaSig @@QAEIXZ+0 x17, calling ?SizeOf@SigPointer@@QBEIPA VModule@@P BVSigTypeC ontext@@@Z
0012eb90 79e88888 ?CalculateHasFPReturn@Meta Sig@@QAEXX Z+0x8, calling ?GetReturnTypeNormalized@M etaSig@@QB E?AW4CorEl ementType@ @XZ
0012eb98 79e88a0d ?ForceSigWalk@MetaSig@@QAE XH@Z+0x19d , calling ?CalculateHasFPReturn@Meta Sig@@QAEXX Z
0012ec2c 79e8a67b ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 84, calling ?Collapse@StackingAllocato r@@QAEXPAX @Z
0012ec40 79e8a69e ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 79d, calling @__security_check_cookie@4
0012ec44 7c80262a _WaitForSingleObjectEx@12+ 0xe5, calling _RtlDeactivateActivationCo ntextUnsaf eFast@4
0012ec88 79ef7fde ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z+0 xf9, calling ?ExecuteCodeWithGuaranteed CleanupHel per@@YGXPA UECWGC_GC@ @@Z
0012ecd0 79ef7f1e ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z+0 x28, calling @LazyMachStateCaptureState @4
0012ed38 793684fb (MethodDesc 0x7913f3d8 +0xa7 System.Threading.Execution Context.Ru nInternal( System.Thr eading.Exe cutionCont ext, System.Threading.ContextCa llback, System.Object)), calling ?ExecuteCodeWithGuaranteed Cleanup@Re flectionIn vocation@@ SIXPAVObje ct@@00@Z
0012ed50 793683ee (MethodDesc 0x7913f3d0 +0x92 System.Threading.Execution Context.Ru n(System.T hreading.E xecutionCo ntext, System.Threading.ContextCa llback, System.Object)), calling (MethodDesc 0x7913f3d8 +0 System.Threading.Execution Context.Ru nInternal( System.Thr eading.Exe cutionCont ext, System.Threading.ContextCa llback, System.Object))
0012ed68 7b06ed78 (MethodDesc 0x7b4a6450 +0x90 System.Windows.Forms.Contr ol.InvokeM arshaledCa llback(Thr eadMethodE ntry)), calling (MethodDesc 0x7913f3d0 +0 System.Threading.Execution Context.Ru n(System.T hreading.E xecutionCo ntext, System.Threading.ContextCa llback, System.Object))
0012ed84 7b06ea6b (MethodDesc 0x7b5a5f88 +0xb3 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbacks()) , calling (MethodDesc 0x7b4a6450 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llback(Thr eadMethodE ntry))
0012edbc 7b072f30 (MethodDesc 0x7b5a5a50 +0x800 System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef)), calling (MethodDesc 0x7b5a5f88 +0 System.Windows.Forms.Contr ol.InvokeM arshaledCa llbacks())
0012ee20 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef)), calling (MethodDesc 0x7b5a5a50 +0 System.Windows.Forms.Contr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012ee28 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef)), calling (MethodDesc 0x7b5a5588 +0 System.Windows.Forms.Scrol lableContr ol.WndProc (System.Wi ndows.Form s.Message ByRef))
0012ee2c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form. WndProc(Sy stem.Windo ws.Forms.M essage ByRef)), calling (MethodDesc 0x7b4a5910 +0 System.Windows.Forms.Conta inerContro l.WndProc( System.Win dows.Forms .Message ByRef))
0012ee3c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr ol+Control NativeWind ow.OnMessa ge(System. Windows.Fo rms.Messag e ByRef))
0012ee40 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr ol+Control NativeWind ow.WndProc (System.Wi ndows.Form s.Message ByRef)), calling 0093704e
0012ee54 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr, Int32, IntPtr, IntPtr))
0012ee94 79e88f63 _CallDescrWorker@20+0x33
0012eeb0 79e88ee4 _CallDescrWorkerWithHandle r@24+0xa3, calling _CallDescrWorker@20
0012ef30 79f2905b ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z+0x55, calling _CallDescrWorkerWithHandle r@24
0012ef50 79f29369 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 x1e5, calling ?ForwardCallToManagedMetho d@@YG_KPBE PA_KIHPAVM etaSig@@PA UArgumentR egisters@@ PAXPAEIPAU UnmanagedT oManagedCa llGCInfo@@ @Z
0012efb8 79f29249 ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z+0 xc3, calling __alloca_probe_16
0012efe8 79e8b035 ?RunML@@YGPBEPBEPBXPAXQAEQ AVCleanupW orkList@@@ Z+0x1313, calling @__security_check_cookie@4
0012efec 79e89233 ?Collapse@StackingAllocato r@@QAEXPAX @Z+0x1c, calling ?Clear@StackingAllocator@@ AAEXPAUSta ckBlock@@@ Z
0012f000 79e8a67b ?Cleanup@CleanupWorkList@@ QAGXH@Z+0x 84, calling ?Collapse@StackingAllocato r@@QAEXPAX @Z
0012f054 79f29143 ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z+0x3 8b, calling ?DoUMThunkCallWorker@@YG_J PAVThread@ @PAVUMThkC allFrame@@ PBVUMEntry Thunk@@PAV UMThunkMar shInfo@@PA UUMThunkML Stub@@@Z
0012f0e0 79f75cc2 ?RareDisablePreemptiveGC@T hread@@QAE XXZ+0x3c6, calling _RtlRestoreLastWin32Error@ 4
0012f118 79fdfe26 _StubRareDisableTHROWWorke r@8+0x5d, calling ?HandleThreadAbort@Thread@ @QAEXH@Z
0012f11c 79fdfe35 _StubRareDisableTHROWWorke r@8+0x6c, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
0012f12c 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr ead@@PAVUM ThkCallFra me@@@Z
0012f15c 7e418734 _InternalCallWinProc@20+0x 28
0012f17c 7e418734 _InternalCallWinProc@20+0x 28
0012f1a8 7e418816 _UserCallWinProcCheckWow@3 2+0x150, calling _InternalCallWinProc@20
0012f210 7e4189cd _DispatchMessageWorker@8+0 x306, calling _UserCallWinProcCheckWow@3 2
0012f270 7e418a10 _DispatchMessageW@4+0xf, calling _DispatchMessageWorker@8
0012f280 79ef064c _NDirectGenericStubReturnF romCall@0
0012f2a4 0091a0ef 0091a0ef, calling _NDirectGenericStubWorker@ 8
0012f2d0 7b084766 (MethodDesc 0x7b5adea8 +0x2ea System.Windows.Forms.Appli cation+Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32, Int32, Int32)), calling 7b64e3d4
0012f2f0 7b084766 (MethodDesc 0x7b5adea8 +0x2ea System.Windows.Forms.Appli cation+Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32, Int32, Int32)), calling 7b64e3d4
0012f308 7b08491c (MethodDesc 0x7b5adea8 +0x4a0 System.Windows.Forms.Appli cation+Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32, Int32, Int32)), calling _NtUserWaitMessage@0
0012f388 7b08432d (MethodDesc 0x7b5ab448 +0x17d System.Windows.Forms.Appli cation+Thr eadContext .RunMessag eLoopInner (Int32, System.Windows.Forms.Appli cationCont ext)), calling 00937152
0012f3f8 7b08416b (MethodDesc 0x7b4a8770 +0x53 System.Windows.Forms.Appli cation+Thr eadContext .RunMessag eLoop(Int3 2, System.Windows.Forms.Appli cationCont ext)), calling (MethodDesc 0x7b5ab448 +0 System.Windows.Forms.Appli cation+Thr eadContext .RunMessag eLoopInner (Int32, System.Windows.Forms.Appli cationCont ext))
0012f428 7b0c69fe (MethodDesc 0x7b4a7670 +0x2e System.Windows.Forms.Appli cation.Run (System.Wi ndows.Form s.Form)), calling 7b64f868
0012f43c 012300af (MethodDesc 0x923000 +0x3f DeadLockWaitOne.Program.Ma in(System. String[])) , calling (MethodDesc 0x7b4a7670 +0 System.Windows.Forms.Appli cation.Run (System.Wi ndows.Form s.Form))
.... (more stack - i've cut the unmanaged stack up until the application.run)
First, i'm sorry if my post is so long - i cannot express everything in just a few words.
mastoo, they are beeing processed by the message pump of WaitOne. when i simply let the app run without any intervention, i get the folowing output:
Entering... 1
Entering... 2
Entering... 3
Entering... 4
Entering... 5
Entering... 1
Entered 1 - 1 time
Doing something meaningfull for call #1
Exited 1 - 1 time
Entering... 2
Entered 2 - 1 time
Doing something meaningfull for call #2
Exited 2 - 1 time
Entering... 3
Entered 3 - 1 time
Doing something meaningfull for call #3
Exited 3 - 1 time
Entering... 4
Entered 4 - 1 time
Doing something meaningfull for call #4
Exited 4 - 1 time
Entering... 5
Entered 5 - 1 time
Doing something meaningfull for call #5
Exited 5 - 1 time
if while waiting in the first invoke i right click on the taskbar icon of the app i get this (please notice the order the invokes get executed - the order of messages 'Doing something meaningfull for call #X'):
Entering... 1
Entering... 2
Entering... 3
Entering... 4
Entering... 5
Entering... 1
Entered 1 - 1 time
Entering... 2
Entered 2 - 2 time
Doing something meaningfull for call #2
Exited 2 - 2 time
Entering... 3
Entered 3 - 2 time
Doing something meaningfull for call #3
Exited 3 - 2 time
Entering... 4
Entered 4 - 2 time
Doing something meaningfull for call #4
Exited 4 - 2 time
Entering... 5
Entered 5 - 2 time
Doing something meaningfull for call #5
Exited 5 - 2 time
Doing something meaningfull for call #1
Exited 1 - 1 time
also notice that when i right click on the taskbar icon while the STA thread is in the wait one, the seccond invoke starts executing before the first has finished:
......
Entering... 1
Entered 1 - 1 time
Entering... 2
Entered 2 - 2 time
Doing something meaningfull for call #2
Exited 2 - 2 time
......
if i stop in the debugger at this point i see this stack (i've marked with '>>>' the 2 calls to Form1.test on the stack - notice how the second one starts from the waitOne):
      [In a sleep, wait, or join]     Â
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
>>>>DeadLockWaitOne.exe!De
      mscorlib.dll!System.Delega
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
>>>>DeadLockWaitOne.exe!De
      mscorlib.dll!System.Delega
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      mscorlib.dll!System.Thread
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      [Native to Managed Transition]     Â
      user32.dll!_InternalCallWi
      user32.dll!_UserCallWinPro
      user32.dll!_DispatchMessag
      user32.dll!_DispatchMessag
      [Managed to Native Transition]     Â
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      System.Windows.Forms.dll!S
      DeadLockWaitOne.exe!DeadLo
      mscoree.dll!__CorExeMain@0
      kernel32.dll!_BaseProcessS
now, if i look into the unmanaged stack to see why it has processed something else while doing waitOne i see the stack bellow. sorry it's so long. notice how after each WaitOne a meesage loop is started and also notice the message that is processed by this meesage loop while in WaitOne. i've also marked with >>>Â the lines with the calls to Form1.test
OS Thread Id: 0x144c (5196)
Current frame: _KiFastSystemCallRet@0
ChildEBP RetAddr  Caller,Callee
0012c250 7c90df2c _NtWaitForMultipleObjects@
0012c254 7c809574 _WaitForMultipleObjectsEx@
0012c280 7e4193e9 _NtUserPeekMessage@20+0xc
0012c284 7e4193a8 __PeekMessage@24+0x74, calling _NtUserPeekMessage@20
0012c2ac 7e419402 _PeekMessageW@20+0xbc, calling __PeekMessage@24
0012c2d8 7755b2bc ?MyPeekMessage@CCliModalLo
0012c2f0 7e4195f9 _RealMsgWaitForMultipleObj
0012c31c 7752f0b8 ?MyPeekMessage@CCliModalLo
0012c320 7752f0f0 ?PeekRPCAndDDEMessage@CCli
0012c34c 7752ebd6 ?BlockFn@CCliModalLoop@@QA
0012c374 77557237 _CoWaitForMultipleHandles@
0012c3e8 79f27b88 ?NT5WaitRoutine@@YGKHKHPAP
0012c400 79f17565 ?GetFinalApartment@Thread@
0012c408 79f27acf ?MsgWaitHelper@@YGKHPAPAXH
0012c45c 79f17565 ?GetFinalApartment@Thread@
0012c474 79f27a33 ?DoAppropriateAptStateWait
0012c494 79f17493 ?DoAppropriateWaitWorker@T
0012c518 79f1732f ?DoAppropriateWait@Thread@
0012c550 79ef5723 ?AcquireSafeHandle@@YGXPAP
0012c568 7a07b49c ?CorWaitOneNative@WaitHand
0012c5c4 7a07b2dd ?CorWaitOneNative@WaitHand
0012c628 7a080550 ?Start@ThreadNative@@SIXPA
0012c66c 793d424e (MethodDesc 0x7924ad60 +0x2e System.Threading.WaitHandl
0012c684 793d4193 (MethodDesc 0x7924ad48 +0x23 System.Threading.WaitHandl
0012c698 793d420e (MethodDesc 0x7924ad58 +0xa System.Threading.WaitHandl
>>>>0012c6a0 012305e7 (MethodDesc 0x925928 +0x1cf DeadLockWaitOne.Form1.test
0012c6c0 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr
0012c6d0 7b08b889 (MethodDesc 0x7b4a7d70 +0xb9 System.Windows.Forms.Nativ
0012c6f0 79e7c2ca ?SkipExactlyOne@SigParser@
0012c720 79e88f63 _CallDescrWorker@20+0x33
0012c730 79e88ee4 _CallDescrWorkerWithHandle
0012c7b0 79e88e31 ?CallDescr@MethodDesc@@AAE
0012c7e0 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x
0012c7ec 79e88db3 ?CallDescr@MethodDesc@@AAE
0012c7f8 79e88dc3 ?CallDescr@MethodDesc@@AAE
0012c85c 79e74c1c ?Alloc@@YGPAVObject@@IHH@Z
0012c874 79f18839 ?JIT_MonReliableEnter@@YIX
0012c878 79e74ebd ?LazyInit@HelperMethodFram
0012c890 79e8a1af ??0HelperMethodFrame_1OBJ@
0012c8ac 79e88d3b ?CallDescr@MethodDesc@@AAE
0012c8f0 79e88d19 ?CallTargetWorker@MethodDe
0012c908 79e88cf6 ?Call@MethodDescCallSite@@
0012c91c 7a11ae16 ?InvokeImpl@@YGPAVObject@@
0012c938 7a11ac68 ?InvokeImpl@@YGPAVObject@@
0012c9b0 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr
0012caac 79e74c1c ?Alloc@@YGPAVObject@@IHH@Z
0012cac4 79f18839 ?JIT_MonReliableEnter@@YIX
0012cac8 79e74ebd ?LazyInit@HelperMethodFram
0012cae0 79e8a1af ??0HelperMethodFrame_1OBJ@
0012cb04 7a11b0fa ?InvokeMethodFast@RuntimeM
0012cb60 7a11b05e ?InvokeMethodFast@RuntimeM
0012cbc4 793cf629 (MethodDesc 0x79248640 +0x49 System.RuntimeMethodHandle
0012cc10 794012bf (MethodDesc 0x79242888 +0x167 System.Reflection.RuntimeM
0012cc48 793ac0fa (MethodDesc 0x7923bbd8 +0x5a System.Delegate.DynamicInv
0012cc70 7b06ec1d (MethodDesc 0x7b5a5f80 +0x9d System.Windows.Forms.Contr
0012cc74 79362186 (MethodDesc 0x7924b598 +0x3e System.Threading.Synchroni
0012cc94 7b06eca7 (MethodDesc 0x7b5a5f78 +0x6b System.Windows.Forms.Contr
0012ccc0 793685af (MethodDesc 0x7913f3e0 +0x43 System.Threading.Execution
0012ccd0 79e88f63 _CallDescrWorker@20+0x33
0012cce0 79e88ee4 _CallDescrWorkerWithHandle
0012cd60 79e88e31 ?CallDescr@MethodDesc@@AAE
0012cd90 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x
0012cd9c 79e88db3 ?CallDescr@MethodDesc@@AAE
0012cda8 79e88dc3 ?CallDescr@MethodDesc@@AAE
0012ce0c 79e8a69e ?Cleanup@CleanupWorkList@@
0012ce24 79f293b7 ?DoUMThunkCallWorker@@YG_J
0012ce28 79f29143 ?DoUMThunkCall@@YG_JPAVThr
0012ce5c 79e88d3b ?CallDescr@MethodDesc@@AAE
0012cea0 79e88d19 ?CallTargetWorker@MethodDe
0012ceb8 79e88cf6 ?Call@MethodDescCallSite@@
0012cecc 79ef80d3 ?ExecuteCodeWithGuaranteed
0012cf94 79e88805 ?SizeOf@SigPointer@@QBEIPA
0012cf98 79e816f7 ?GetReturnTypeSize@MetaSig
0012cfa0 79e88888 ?CalculateHasFPReturn@Meta
0012cfa8 79e88a0d ?ForceSigWalk@MetaSig@@QAE
0012d040 79e8a69e ?Cleanup@CleanupWorkList@@
0012d058 79f293b7 ?DoUMThunkCallWorker@@YG_J
0012d05c 79f29143 ?DoUMThunkCall@@YG_JPAVThr
0012d098 79ef7fde ?ExecuteCodeWithGuaranteed
0012d0e0 79ef7f1e ?ExecuteCodeWithGuaranteed
0012d148 793684fb (MethodDesc 0x7913f3d8 +0xa7 System.Threading.Execution
0012d160 793683ee (MethodDesc 0x7913f3d0 +0x92 System.Threading.Execution
0012d178 7b06ed78 (MethodDesc 0x7b4a6450 +0x90 System.Windows.Forms.Contr
0012d194 7b06ea6b (MethodDesc 0x7b5a5f88 +0xb3 System.Windows.Forms.Contr
0012d1cc 7b072f30 (MethodDesc 0x7b5a5a50 +0x800 System.Windows.Forms.Contr
0012d230 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol
0012d238 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta
0012d23c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form.
0012d24c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr
0012d250 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr
0012d264 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ
0012d28c 7a4a6956 (MethodDesc 0x7a7ffbb8 +0x26 System.ComponentModel.Even
0012d2a4 79e88f63 _CallDescrWorker@20+0x33
0012d2b4 7b05f80e (MethodDesc 0x7b4a6478 +0x32 System.Windows.Forms.Contr
0012d2c0 79e88ee4 _CallDescrWorkerWithHandle
0012d340 79f2905b ?ForwardCallToManagedMetho
0012d360 79f29369 ?DoUMThunkCallWorker@@YG_J
0012d3c8 79f29249 ?DoUMThunkCallWorker@@YG_J
0012d404 7b0814c3 (MethodDesc 0x7b5ab7c0 +0x2b System.Windows.Forms.Butto
0012d40c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr
0012d410 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr
0012d464 79f29143 ?DoUMThunkCall@@YG_JPAVThr
0012d498 7c949a41 _RtlAllocateHeapSlowly@12+
0012d4a0 7c91925d _RtlAllocateHeapSlowly@12+
0012d4a4 7c9192ef _RtlAllocateHeapSlowly@12+
0012d4f0 79f75cc2 ?RareDisablePreemptiveGC@T
0012d528 79fdfe26 _StubRareDisableTHROWWorke
0012d52c 79fdfe35 _StubRareDisableTHROWWorke
0012d53c 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr
0012d56c 7e418734 _InternalCallWinProc@20+0x
0012d58c 7e418734 _InternalCallWinProc@20+0x
0012d5b8 7e418816 _UserCallWinProcCheckWow@3
0012d608 7e42b372 _DispatchHookW@16+0x31
0012d620 7e428ea0 _DispatchClientMessage@20+
0012d65c 7e42b326 _CallHookWithSEH@16+0x44, calling __SEH_epilog
0012d674 7e428eec ___fnDWORD@4+0x24
0012d6c0 7e4194be _NtUserMessageCall@28+0xc
0012d6f0 79fdfe35 _StubRareDisableTHROWWorke
0012d700 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr
0012d714 7e428dd9 _RealDefWindowProcW@16+0x4
0012d730 7e428d77 _DefWindowProcW@16+0x72, calling _RealDefWindowProcW@16
0012d778 7e418734 _InternalCallWinProc@20+0x
0012d7a4 7e418816 _UserCallWinProcCheckWow@3
0012d7f4 79e8e1cf ?HandleThreadAbort@Thread@
0012d80c 7e42a013 _CallWindowProcAorW@24+0x9
0012d83c 7e42a039 _CallWindowProcW@20+0x1b, calling _CallWindowProcAorW@24
0012d85c 7b07a7d4 (MethodDesc 0x7b4a7d78 +0x94 System.Windows.Forms.Nativ
0012d888 7b07a7d4 (MethodDesc 0x7b4a7d78 +0x94 System.Windows.Forms.Nativ
0012d894 79e8a67b ?Cleanup@CleanupWorkList@@
0012d8b4 7b05ed83 (MethodDesc 0x7b4a56b0 +0x87 System.Windows.Forms.Form.
0012d8fc 7b072faa (MethodDesc 0x7b5a5a50 +0x87a System.Windows.Forms.Contr
0012d960 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol
0012d968 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta
0012d96c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form.
0012d97c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr
0012d980 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr
0012d994 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ
0012d9d4 79e88f63 _CallDescrWorker@20+0x33
0012d9f0 79e88ee4 _CallDescrWorkerWithHandle
0012da58 7c802600 _WaitForSingleObjectEx@12+
0012da70 79f2905b ?ForwardCallToManagedMetho
0012da90 79f29369 ?DoUMThunkCallWorker@@YG_J
0012dafc 79f29249 ?DoUMThunkCallWorker@@YG_J
0012db98 79f29143 ?DoUMThunkCall@@YG_JPAVThr
0012dbc4 7c90da0c _NtReleaseMutant@8+0xc
0012dbc8 7c8024c7 _ReleaseMutex@4+0x10, calling _NtReleaseMutant@8
0012dbd8 7475577a ?Leave@CTimList@@QAEXXZ+0x
0012dbe0 74755d2a ?GetDWORD@CTimList@@AAEKKW
0012dc24 79f75cc2 ?RareDisablePreemptiveGC@T
0012dc5c 79fdfe26 _StubRareDisableTHROWWorke
0012dc60 79fdfe35 _StubRareDisableTHROWWorke
0012dc70 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr
0012dca0 7e418734 _InternalCallWinProc@20+0x
0012dcc0 7e418734 _InternalCallWinProc@20+0x
0012dcec 7e418816 _UserCallWinProcCheckWow@3
0012dd54 7e428ea0 _DispatchClientMessage@20+
0012dd84 7e42b317 _CallHookWithSEH@16+0x21
0012dda8 7e428eec ___fnDWORD@4+0x24
0012ddc0 7e4278d0 ___fnHkINLPMSG@4+0x25, calling _CallHookWithSEH@16
0012ddf4 7e4193e9 _NtUserPeekMessage@20+0xc
0012ddf8 7e4193a8 __PeekMessage@24+0x74, calling _NtUserPeekMessage@20
0012de20 7e419402 _PeekMessageW@20+0xbc, calling __PeekMessage@24
0012de4c 7755b2bc ?MyPeekMessage@CCliModalLo
0012de94 7752f0f0 ?PeekRPCAndDDEMessage@CCli
0012dec8 7755b2bc ?MyPeekMessage@CCliModalLo
0012ded4 7752f1ef ?FindMessage@CCliModalLoop
0012dee0 7e4195f9 _RealMsgWaitForMultipleObj
0012deec 7e4184ce _NtUserCallNoParam@4+0xc
0012def0 7e4184ba _NtUserCallOneParam@8+0xc
0012def4 7e42ae7a _RealGetQueueStatus@4+0x26
0012df04 7752f28f ?HandleWakeForMsg@CCliModa
0012df50 7752f23e ?BlockFn@CCliModalLoop@@QA
0012df64 77557237 _CoWaitForMultipleHandles@
0012dfd8 79f27b88 ?NT5WaitRoutine@@YGKHKHPAP
0012dff0 79f17565 ?GetFinalApartment@Thread@
0012dff8 79f27acf ?MsgWaitHelper@@YGKHPAPAXH
0012e04c 79f17565 ?GetFinalApartment@Thread@
0012e064 79f27a33 ?DoAppropriateAptStateWait
0012e084 79f17493 ?DoAppropriateWaitWorker@T
0012e108 79f1732f ?DoAppropriateWait@Thread@
0012e140 79ef5723 ?AcquireSafeHandle@@YGXPAP
0012e158 7a07b49c ?CorWaitOneNative@WaitHand
0012e1b4 7a07b2dd ?CorWaitOneNative@WaitHand
0012e218 7a080550 ?Start@ThreadNative@@SIXPA
0012e25c 793d424e (MethodDesc 0x7924ad60 +0x2e System.Threading.WaitHandl
0012e274 793d4193 (MethodDesc 0x7924ad48 +0x23 System.Threading.WaitHandl
0012e288 793d420e (MethodDesc 0x7924ad58 +0xa System.Threading.WaitHandl
>>>>Â 0012e290 012305e7 (MethodDesc 0x925928 +0x1cf DeadLockWaitOne.Form1.test
0012e2d4 79e7bbb1 _PreStubWorker@4+0x138, calling __EH_epilog3
0012e2d8 00351f3e 00351f3e, calling _PreStubWorker@4
0012e310 79e88f63 _CallDescrWorker@20+0x33
0012e318 7c949a41 _RtlAllocateHeapSlowly@12+
0012e320 79e88ee4 _CallDescrWorkerWithHandle
0012e3a0 79e88e31 ?CallDescr@MethodDesc@@AAE
0012e3d0 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x
0012e3dc 79e88db3 ?CallDescr@MethodDesc@@AAE
0012e3e8 79e88dc3 ?CallDescr@MethodDesc@@AAE
0012e464 79e74753 ?Leave@CrstBase@@AAEXXZ+0x
0012e468 79e74ebd ?LazyInit@HelperMethodFram
0012e480 79e8a1af ??0HelperMethodFrame_1OBJ@
0012e49c 79e88d3b ?CallDescr@MethodDesc@@AAE
0012e4e0 79e88d19 ?CallTargetWorker@MethodDe
0012e4f8 79e88cf6 ?Call@MethodDescCallSite@@
0012e50c 7a11ae16 ?InvokeImpl@@YGPAVObject@@
0012e528 7a11ac68 ?InvokeImpl@@YGPAVObject@@
0012e5c4 79e7d329 ?GetTypeHandleThrowing@Sig
0012e5c8 79eec9b8 ?GetLastTypeHandleThrowing
0012e6b4 79e74753 ?Leave@CrstBase@@AAEXXZ+0x
0012e6b8 79e74ebd ?LazyInit@HelperMethodFram
0012e6d0 79e8a1af ??0HelperMethodFrame_1OBJ@
0012e6f4 7a11b0fa ?InvokeMethodFast@RuntimeM
0012e750 7a11b05e ?InvokeMethodFast@RuntimeM
0012e7b4 793cf629 (MethodDesc 0x79248640 +0x49 System.RuntimeMethodHandle
0012e800 794012bf (MethodDesc 0x79242888 +0x167 System.Reflection.RuntimeM
0012e838 793ac0fa (MethodDesc 0x7923bbd8 +0x5a System.Delegate.DynamicInv
0012e860 7b06ec1d (MethodDesc 0x7b5a5f80 +0x9d System.Windows.Forms.Contr
0012e864 79362186 (MethodDesc 0x7924b598 +0x3e System.Threading.Synchroni
0012e884 7b06eca7 (MethodDesc 0x7b5a5f78 +0x6b System.Windows.Forms.Contr
0012e8b0 793685af (MethodDesc 0x7913f3e0 +0x43 System.Threading.Execution
0012e8c0 79e88f63 _CallDescrWorker@20+0x33
0012e8d0 79e88ee4 _CallDescrWorkerWithHandle
0012e950 79e88e31 ?CallDescr@MethodDesc@@AAE
0012e980 79e88fe3 ??0MetaSig@@QAE@PAV0@@Z+0x
0012e98c 79e88db3 ?CallDescr@MethodDesc@@AAE
0012e998 79e88dc3 ?CallDescr@MethodDesc@@AAE
0012e9f8 79e8a67b ?Cleanup@CleanupWorkList@@
0012ea0c 79e8a69e ?Cleanup@CleanupWorkList@@
0012ea10 7c80262a _WaitForSingleObjectEx@12+
0012ea4c 79e88d3b ?CallDescr@MethodDesc@@AAE
0012ea90 79e88d19 ?CallTargetWorker@MethodDe
0012eaa8 79e88cf6 ?Call@MethodDescCallSite@@
0012eabc 79ef80d3 ?ExecuteCodeWithGuaranteed
0012eb84 79e88805 ?SizeOf@SigPointer@@QBEIPA
0012eb88 79e816f7 ?GetReturnTypeSize@MetaSig
0012eb90 79e88888 ?CalculateHasFPReturn@Meta
0012eb98 79e88a0d ?ForceSigWalk@MetaSig@@QAE
0012ec2c 79e8a67b ?Cleanup@CleanupWorkList@@
0012ec40 79e8a69e ?Cleanup@CleanupWorkList@@
0012ec44 7c80262a _WaitForSingleObjectEx@12+
0012ec88 79ef7fde ?ExecuteCodeWithGuaranteed
0012ecd0 79ef7f1e ?ExecuteCodeWithGuaranteed
0012ed38 793684fb (MethodDesc 0x7913f3d8 +0xa7 System.Threading.Execution
0012ed50 793683ee (MethodDesc 0x7913f3d0 +0x92 System.Threading.Execution
0012ed68 7b06ed78 (MethodDesc 0x7b4a6450 +0x90 System.Windows.Forms.Contr
0012ed84 7b06ea6b (MethodDesc 0x7b5a5f88 +0xb3 System.Windows.Forms.Contr
0012edbc 7b072f30 (MethodDesc 0x7b5a5a50 +0x800 System.Windows.Forms.Contr
0012ee20 7b07f795 (MethodDesc 0x7b5a5588 +0x45 System.Windows.Forms.Scrol
0012ee28 7b07f743 (MethodDesc 0x7b4a5910 +0x13 System.Windows.Forms.Conta
0012ee2c 7b063fc6 (MethodDesc 0x7b4a5550 +0x2b6 System.Windows.Forms.Form.
0012ee3c 7b07a72d (MethodDesc 0x7b5a8168 +0xd System.Windows.Forms.Contr
0012ee40 7b07a706 (MethodDesc 0x7b5a8180 +0xd6 System.Windows.Forms.Contr
0012ee54 7b08b845 (MethodDesc 0x7b4a7d70 +0x75 System.Windows.Forms.Nativ
0012ee94 79e88f63 _CallDescrWorker@20+0x33
0012eeb0 79e88ee4 _CallDescrWorkerWithHandle
0012ef30 79f2905b ?ForwardCallToManagedMetho
0012ef50 79f29369 ?DoUMThunkCallWorker@@YG_J
0012efb8 79f29249 ?DoUMThunkCallWorker@@YG_J
0012efe8 79e8b035 ?RunML@@YGPBEPBEPBXPAXQAEQ
0012efec 79e89233 ?Collapse@StackingAllocato
0012f000 79e8a67b ?Cleanup@CleanupWorkList@@
0012f054 79f29143 ?DoUMThunkCall@@YG_JPAVThr
0012f0e0 79f75cc2 ?RareDisablePreemptiveGC@T
0012f118 79fdfe26 _StubRareDisableTHROWWorke
0012f11c 79fdfe35 _StubRareDisableTHROWWorke
0012f12c 003521f6 003521f6, calling ?DoUMThunkCall@@YG_JPAVThr
0012f15c 7e418734 _InternalCallWinProc@20+0x
0012f17c 7e418734 _InternalCallWinProc@20+0x
0012f1a8 7e418816 _UserCallWinProcCheckWow@3
0012f210 7e4189cd _DispatchMessageWorker@8+0
0012f270 7e418a10 _DispatchMessageW@4+0xf, calling _DispatchMessageWorker@8
0012f280 79ef064c _NDirectGenericStubReturnF
0012f2a4 0091a0ef 0091a0ef, calling _NDirectGenericStubWorker@
0012f2d0 7b084766 (MethodDesc 0x7b5adea8 +0x2ea System.Windows.Forms.Appli
0012f2f0 7b084766 (MethodDesc 0x7b5adea8 +0x2ea System.Windows.Forms.Appli
0012f308 7b08491c (MethodDesc 0x7b5adea8 +0x4a0 System.Windows.Forms.Appli
0012f388 7b08432d (MethodDesc 0x7b5ab448 +0x17d System.Windows.Forms.Appli
0012f3f8 7b08416b (MethodDesc 0x7b4a8770 +0x53 System.Windows.Forms.Appli
0012f428 7b0c69fe (MethodDesc 0x7b4a7670 +0x2e System.Windows.Forms.Appli
0012f43c 012300af (MethodDesc 0x923000 +0x3f DeadLockWaitOne.Program.Ma
.... (more stack - i've cut the unmanaged stack up until the application.run)
Interesting. Â I'll try to read this over lunch today.
I stand corrected. Â It does exactly what you describe. Â I'm sure you already deduced this but I gather it must go something like this:
Your worker thread does the invokes, queuing up messages for the pump.
The pump causes the first queued call to start.
It gets to the wait and must not check the pump if no messages have come in, but since the windows message happens it goes ahead with the next message (your call #2).
And now call #2 is chugging along before #1 exits the wait.
So the bottom line is how do you stop that behavior without modifying a bunch of your code? Â Can you just change to MTA instead of STA? Â It works as advertised, with no pumping (and of course an unresponsive gui). Â It shouldn't matter unless you're doing COM.
Your worker thread does the invokes, queuing up messages for the pump.
The pump causes the first queued call to start.
It gets to the wait and must not check the pump if no messages have come in, but since the windows message happens it goes ahead with the next message (your call #2).
And now call #2 is chugging along before #1 exits the wait.
So the bottom line is how do you stop that behavior without modifying a bunch of your code? Â Can you just change to MTA instead of STA? Â It works as advertised, with no pumping (and of course an unresponsive gui). Â It shouldn't matter unless you're doing COM.
ASKER
unfortunately my app is realy huge, it has multiple modules and some require this thread to be STA. i tried it and changing to MTA does not work for me... :(
Sorry, I can't think of an easy fix. Â The only thing I can think of would be maybe the below, just in case you are desperate...
Global replace of System.Threading.AutoReset Event declarations to reference your own class, and you write a class that does a different kind of wait. Â Your class could sleep and periodically check a synchronized bool, which I don't believe runs the pump.
Global replace of System.Threading.AutoReset
ASKER
i stopped looking for an easy fix long ago :)
so if you have any ideas they are welcomed
thanks,
A.
so if you have any ideas they are welcomed
thanks,
A.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
after investigating this for a while i found it to be a bug in .net
so, like MS said, no work-around, i should change the design.
so, like MS said, no work-around, i should change the design.
at the top of your method.