F
Francois Tanguay
Create a Form. Drop a List Box. Add items to the listbox. Observe ListBox.SelectedIndexChange
Create a Web Service with a method that does some fake processing in order to simulate some delay with a serve
[WebMethod] public string HelloWorld(){ System.Threading.Thread.Sleep(2000); return "Hello World";
Call the web service in SelectedIndexChanged
private void ListBox_SelectedIndexChanged(object sender, EventArgs e) { new localHost.Service().HelloWorld();
Now, if you press the down arrow quickly enough, messages will be added to the MSG pump. However, the following thing occurs: When the WebService is called, it somehow forces the Application to process the messages on hold in the pump (Something like Application.DoEvents() would have been called
This means that ListBox_SelectedIndexChanged will be called in a reentrant way when the WebService is called
ListBox_SelectedIndexChange
Service1.HelloWorl
ListBox_SelectedIndexChange
Service1.HelloWorld..
instead of
ListBox_SelectedIndexChange
Service1.HelloWorl
ListBox_SelectedIndexChange
Service1.HelloWorl
Here's the stack trace
at WindowsApplication21.Form1.listBox1_SelectedIndexChanged(Object sender, EventArgs e
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e
at System.Windows.Forms.ListBox.WmReflectCommand(Message& m
at System.Windows.Forms.ListBox.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m
at System.Windows.Forms.Control.WmCommand(Message& m
at System.Windows.Forms.Control.WndProc(Message& m
at System.Windows.Forms.ScrollableControl.WndProc(Message& m
at System.Windows.Forms.ContainerControl.WndProc(Message& m
at System.Windows.Forms.Form.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m
at System.Windows.Forms.Control.DefWndProc(Message& m
at System.Windows.Forms.Control.WmKeyChar(Message& m
at System.Windows.Forms.Control.WndProc(Message& m
at System.Windows.Forms.ListBox.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Web.Services.Interop.INotifySink2.OnSyncCallOut(CallId callId, IntPtr& out_ppBuffer, Int32& inout_pBufferSize
at System.Web.Services.UnsafeNativeMethods.OnSyncCallOut(INotifySink2 sink, CallId callId, IntPtr& out_ppBuffer, Int32& inout_pBufferSize
at System.Web.Services.Protocols.RemoteDebugger.NotifyClientCallOut(WebRequest request
at System.Web.Services.Protocols.WebClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.SoapHttpClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters
at WindowsApplication21.localhost.Service1.HelloWorld(
at WindowsApplication21.Form1.listBox1_SelectedIndexChanged(Object sender, EventArgs e)
Create a Web Service with a method that does some fake processing in order to simulate some delay with a serve
[WebMethod] public string HelloWorld(){ System.Threading.Thread.Sleep(2000); return "Hello World";
Call the web service in SelectedIndexChanged
private void ListBox_SelectedIndexChanged(object sender, EventArgs e) { new localHost.Service().HelloWorld();
Now, if you press the down arrow quickly enough, messages will be added to the MSG pump. However, the following thing occurs: When the WebService is called, it somehow forces the Application to process the messages on hold in the pump (Something like Application.DoEvents() would have been called
This means that ListBox_SelectedIndexChanged will be called in a reentrant way when the WebService is called
ListBox_SelectedIndexChange
Service1.HelloWorl
ListBox_SelectedIndexChange
Service1.HelloWorld..
instead of
ListBox_SelectedIndexChange
Service1.HelloWorl
ListBox_SelectedIndexChange
Service1.HelloWorl
Here's the stack trace
at WindowsApplication21.Form1.listBox1_SelectedIndexChanged(Object sender, EventArgs e
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e
at System.Windows.Forms.ListBox.WmReflectCommand(Message& m
at System.Windows.Forms.ListBox.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m
at System.Windows.Forms.Control.WmCommand(Message& m
at System.Windows.Forms.Control.WndProc(Message& m
at System.Windows.Forms.ScrollableControl.WndProc(Message& m
at System.Windows.Forms.ContainerControl.WndProc(Message& m
at System.Windows.Forms.Form.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m
at System.Windows.Forms.Control.DefWndProc(Message& m
at System.Windows.Forms.Control.WmKeyChar(Message& m
at System.Windows.Forms.Control.WndProc(Message& m
at System.Windows.Forms.ListBox.WndProc(Message& m
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
at System.Web.Services.Interop.INotifySink2.OnSyncCallOut(CallId callId, IntPtr& out_ppBuffer, Int32& inout_pBufferSize
at System.Web.Services.UnsafeNativeMethods.OnSyncCallOut(INotifySink2 sink, CallId callId, IntPtr& out_ppBuffer, Int32& inout_pBufferSize
at System.Web.Services.Protocols.RemoteDebugger.NotifyClientCallOut(WebRequest request
at System.Web.Services.Protocols.WebClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.SoapHttpClientProtocol.GetWebRequest(Uri uri
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters
at WindowsApplication21.localhost.Service1.HelloWorld(
at WindowsApplication21.Form1.listBox1_SelectedIndexChanged(Object sender, EventArgs e)