Async Web service and Form Close()

P

Paul

Hi,

I have a Windows Forms client that calls a web service both synchronously
and asynchronously. If a certain value is returned, I pop up a MessageBox
to the user, and wait for their answer. I set a timer before the window
opens to make sure something happens within a time period. If the timer
does in fact pop, I call this.Close() on the form to close the app.

When the timer pops after a synchronous call to the web service, the close
causes the MessageBox to close, and the Application terminates. But if the
call to the web service is async, a call to this.Close() in the timer
elapsed function closes the form, but the MessageBox remains open (and
subsequently, the app remains resident).

Sync:
------
Call Web Service Sync
Examine result
Set Timer
Open Message Box

Timer Pops
this.Close()

MessageBox Closes, and Application Sucessfully Exits


Async:
-------
Call Begin_Web Service (async)
Async Callback Called
Delegate function invoked
Examine result
Set Timer
Open MessageBox

Timer Pops
this.Close()

Form closes, but MessageBox remains open until user intervention, leaving
the app running.

....
Does anyone have an explanation and method to get the message box to close
(and the app to exit) in the Async case?

Thanks,

-Paul
 
P

Paul

I think I have solved it, although I still have a bit more testing to do. I
was not passing the Form's window handle as the first parameter to the
MessageBox.Show(). I guess it doesn't close the message box as a child
window sometimes when that parameter is passed.

-Paul
 

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