M
Michael C
Hi all,
Is there an easy way to get the parameters of an asynchronous delegate call
from the callback function? Here's an example of what I'm trying to do:
private delegate ArrayList AsyncDelegate (string server);
private void GetServerInfo (string server)
{
AsyncDelegate ad = new AsyncDelegate(GetServerArray);
IAsyncResult iar = ad.BeginInvoke(server, new
AsyncCallback(EndGetServerInfo), ad);
}
private void EndGetServerInfo(IAsyncResult iar)
{
AsyncDelegate ad = (AsyncDelegate)iar.AsyncState;
ArrayList a = ad.EndInvoke(iar);
}
private ArrayList GetServerArray(string server)
{
ArrayList a = new ArrayList();
// this code establishes a SQL connection, executes a
// few queries and .Adds the results to the ArrayList
return (a);
}
In this code, GetServerInfo executes the "GetServerArray" routine
asynchronously. This routine basically connects to a SQL Server, executes a
couple of SELECT statements and returns the results in an ArrayList. After
completion, the EndGetServerInfo is called, and I retrieve the results via
..EndInvoke.
Everything works great, and I get my ArrayList of information, but there's
one small problem: in the EndGetServerInfo callback routine, I need to
retrieve not just the returned ArrayList, but also the initial parameter I
passed into the "GetServerInfo" routine (i.e., the "string server"
variable).
I imagine there's an easy way to do this via the IAsyncResult, but I'm not
sure how. Any ideas? Or would it be easier just to have my
"GetServerArray" routine .Add the value of the "server" variable as the
first item on the returned ArrayList? Seems kind of hokey, and would like
to avoid that if possible.
Thanks,
Michael C., MCDBA
Is there an easy way to get the parameters of an asynchronous delegate call
from the callback function? Here's an example of what I'm trying to do:
private delegate ArrayList AsyncDelegate (string server);
private void GetServerInfo (string server)
{
AsyncDelegate ad = new AsyncDelegate(GetServerArray);
IAsyncResult iar = ad.BeginInvoke(server, new
AsyncCallback(EndGetServerInfo), ad);
}
private void EndGetServerInfo(IAsyncResult iar)
{
AsyncDelegate ad = (AsyncDelegate)iar.AsyncState;
ArrayList a = ad.EndInvoke(iar);
}
private ArrayList GetServerArray(string server)
{
ArrayList a = new ArrayList();
// this code establishes a SQL connection, executes a
// few queries and .Adds the results to the ArrayList
return (a);
}
In this code, GetServerInfo executes the "GetServerArray" routine
asynchronously. This routine basically connects to a SQL Server, executes a
couple of SELECT statements and returns the results in an ArrayList. After
completion, the EndGetServerInfo is called, and I retrieve the results via
..EndInvoke.
Everything works great, and I get my ArrayList of information, but there's
one small problem: in the EndGetServerInfo callback routine, I need to
retrieve not just the returned ArrayList, but also the initial parameter I
passed into the "GetServerInfo" routine (i.e., the "string server"
variable).
I imagine there's an easy way to do this via the IAsyncResult, but I'm not
sure how. Any ideas? Or would it be easier just to have my
"GetServerArray" routine .Add the value of the "server" variable as the
first item on the returned ArrayList? Seems kind of hokey, and would like
to avoid that if possible.
Thanks,
Michael C., MCDBA