V
VR
I am trying to access a web service from a Windows Forms
based app, and I need to make the call to the service
asynchronously, so that a user could stop the call using
UI controls.
I implemented it in MyForm, that has a cancel button --
btnCancel. Is it possible to make sure that in
btnCancel_Click function I can do something that would
prevent the callback event from firing?
Here is the code:
void AccessWebService()
{
AsyncCallback cb = new AsyncCallback(MyCallback);
int iData = 1;
m_oAsyncResult = m_oWebService.BeginAccessWeb(
iData,
cb,
m_oWebService);
}
void MyCallback(IAsyncResult oResult)
{
CWebService oWebService =
(CWebService)oResult.AsyncState;
int iResultData = oWebService.EndAccessWeb(oResult);
}
void btnCancel_Click(object sender, EventArgs e)
{
// ?????
// what can I do here to prevent MyCallback
// from being called?
this.Hide();
}
What can stop MyCallback from being called? Also, I am not
very sure how thread-safe it is to access m_oAsyncResult
in btnCancel_Click(), are btnCancel_Click() and
MyCallback serialized or would MyCallback will be called
from a context of a different thread?
Thanks for any suggestions.
VR
based app, and I need to make the call to the service
asynchronously, so that a user could stop the call using
UI controls.
I implemented it in MyForm, that has a cancel button --
btnCancel. Is it possible to make sure that in
btnCancel_Click function I can do something that would
prevent the callback event from firing?
Here is the code:
void AccessWebService()
{
AsyncCallback cb = new AsyncCallback(MyCallback);
int iData = 1;
m_oAsyncResult = m_oWebService.BeginAccessWeb(
iData,
cb,
m_oWebService);
}
void MyCallback(IAsyncResult oResult)
{
CWebService oWebService =
(CWebService)oResult.AsyncState;
int iResultData = oWebService.EndAccessWeb(oResult);
}
void btnCancel_Click(object sender, EventArgs e)
{
// ?????
// what can I do here to prevent MyCallback
// from being called?
this.Hide();
}
What can stop MyCallback from being called? Also, I am not
very sure how thread-safe it is to access m_oAsyncResult
in btnCancel_Click(), are btnCancel_Click() and
MyCallback serialized or would MyCallback will be called
from a context of a different thread?
Thanks for any suggestions.
VR