Dear Group,
I am calling a webService asynchronously, using a pattern similar to this:
private void button2_Click(object sender, System.EventArgs e)
{
// Disable the Async button and clear the ListView of any data
// Create an instance of XML Web service proxy class
BookCatalog.Service1 ws = new BookCatalog.Service1();
// Create a reference to the callback delegate
AsyncCallback cb = new AsyncCallback(ServiceCallback);
// Call the Begin method, passing the callback delegate and
// this proxy class instance as the AsyncState object.
ws.BeginGetItems(cb,ws);
private void ServiceCallback(IAsyncResult ar)Quote:}
{
// Cast the AsyncState object to the proxy object
BookCatalog.Service1 ws = (BookCatalog.Service1)ar.AsyncState;
// Call the End method and assign the response to a DataSet
this.ds = ws.EndGetItems(ar); //forces to updates the ui in the
corresponding thread this.Invoke(new
EventHandler(this.DataGridUpdater));}
private void DataGridUpdater(object sender, EventArgs ea)
{
this.pctbSalir.Enabled=true;
this.dgSanatorios.DataSource=this.ds.Tables["prestadores"];
this.dgSanatorios.RowHeadersVisible=false;
this.dgSanatorios.Visible=true;
But I have problems when exceptions rise, I have tried to add a try/cathQuote:}
block in te line: ws.BeginGetItems(cb,ws), but exceptions still arise and
make me crash the app. The exceptions I wanna catch are
ObjectDisposedException, and InvalidOperationException and some more which
are thrown when the call to the web service has not been successful.
Diwik