By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,179 Members | 2,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,179 IT Pros & Developers. It's quick & easy.

Calling An Asynchronous Web Service from UI Thread

P: n/a
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

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[
{ = STE.WebClient.JobClient.Client.EndGetBooking(ar);
accountTextBox.Text =;

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

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"

The only way I can see this happening is if the internals of
BeginGetBooking have some kind of Application.DoEvents() call ?

Please Help!


Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.