Hi, I am trying to use an asynchronous call on a web method. The sample code
below shows what I'm trying to do. The web method being called takes 10
seconds to execute, then returns. No matter how long I wait, the callback
does not get called until <ret> is pressed, and have single stepped over the
call to WaitOne.
Am I doing anything obviously wrong ?
TVMIA,
Adam.
private static void w(string s)
{
System.Console.WriteLine(s);
}
public static void asyncCallback_LetsGoBonkers(System.IAsyncResult ar)
{
localhost.Service1 s = (localhost.Service1) ar.AsyncState;
// s.EndLetsGoBonkers(ar);
w("Call back.");
}
[STAThread]
static void Main(string[] args)
{
localhost.Service1 s = new C2.localhost.Service1();
s.Url = http://adam2/WebServiceTest/Service1.asmx;
System.AsyncCallback cb = new
System.AsyncCallback(asyncCallback_LetsGoBonkers);
System.IAsyncResult ias = s.BeginLetsGoBonkers(100, cb, s);
w("Hit RETURN");
System.Console.ReadLine();
w("RETURN pressed.");
bool b = ias.AsyncWaitHandle.WaitOne(10000, false); // Single step on
this line and you end up in the call back
if (b)
{
s.EndLetsGoBonkers(ias);
w("Call ended.");
}
w("Hit RETURN");
System.Console.ReadLine();
w("RETURN pressed.");
}
--
===========================
Adam Benson
Omnibus Systems,
Leics. UK
Email : Ad*********@NOSPAM.omnibus.co.uk