Hi There
This question is about calling an asynchronous web service from the UI
thread. Unless I am making a fundamental error, it appears that the
asynchronous web service call seems to spark off an
Application.DoEvents() when system resources are low and the message
loop has queued requests.
Here are some snippets of code to describe the problem:
The form has a datagrid, which usually contains 1000 or so records. In
the datagrids current cell changed event handler we have:
AsyncCallback myCallBack = new AsyncCallback(WebServiceCallback);
Debug.WriteLine("About to make web service call");
STE.WebClient.JobClient.Client.BeginGetBooking(thi s.ID,myCallBack,new
Object());
Debug.WriteLine("REACHED LINE AFTER WEB SERVICE CALL");
The call back method 'WebServiceCallback' just updates a text box:
public void WebServiceCallback (IAsyncResult ar)
{
if (InvokeRequired)
{
// We're not in the UI thread, so we need to call BeginInvoke
BeginInvoke(new MySpecialDelegate(WebServiceCallback,new object[
{ar});
}
else
{
this.booking = STE.WebClient.JobClient.Client.EndGetBooking(ar);
accountTextBox.Text = this.booking.Status;
}
}
If the user holds down the down arrow key then he/she can scroll down
the datagrid very quickly, resulting in quickfire calls to the web
service. I would expect to see a pattern of debug.write lines where
"About to make web service call" is followed by a corresponding
"REACHED LINE AFTER WEB SERVICE CALL".
The above behavour occurs most of the time. However if I open several
other applications (such as Access, Excel ... ) then repeat the above
experiment, by holding down the arrow key and quickly scrolling down
the datagrid, the "About to make web service call" write lines start to
appear after each other, with no corresponding "REACHED LINE AFTER WEB
SERVICE CALL" messages. After a few hundred of the "About to make web
service call" messages appear the program crashes with "An unhandled
exception of type 'System.StackOverflowException' occurred in
system.windows.forms.dll"
The only way I can see this happening is if the internals of
BeginGetBooking have some kind of Application.DoEvents() call ?
Please Help!
Bill