setting back waitcursor on asynchronous callback

Y

YF

Dear all,

I have a compact framework application that calls a webservice. I call the
webservice asynchronously on a button click event and when the web service
method completes successfully the callback function is successfully called.

The code looks as follows:

---------------------
private void btnRegister_Click(object sender, System.EventArgs e)
{
// set the wait cursor
Cursor.Current = Cursors.WaitCursor;

// component for calling webservice
Worker theWorker = new Worker();

// register the event and pass delegate
theWorker.WebMethodCompletedEvent += new
Worker.WebMethodCompleted(this.registerCompleted);

// call web method
theWorker.ClaimDevice(tbDeviceID.Text);
}

private void registerCompleted(int aResult)
{
// do stuff.

// restore cursor
Cursor.Current = Cursors.Default;
}
---------------------

My problem is that the cursor is not restored to the default cursor after
the callback. I know it's a problem with the async. callback of the
webservice cause if i replace the asynchronous method with a synchronous
method the cursor is restored. But ofcourse i want to keep the webservice
call asynchronous. Does anyone have an idea how i can fix this?

Thanks,
Yang
 
A

Alex Feinman [MVP]

Use Form.Invoke from the callback. In the Invoke target (which by the way
should have EventHandler signature) set the cursor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top