I try to call the BeginInvoke method of a delegate but I get an Exception
"NotSupportedException" when I
execute the program. Here is the code I'm using it is from the MS
helpsystem.
Thankx Thomas
TMS Technical Management Systems GmbH
www.t-m-s.at
using System;
using System.Threading;
public class AsyncDemo
{
// The method to be executed asynchronously.
public string TestMethod ( int callDuration )
{
Console.WriteLine ( "Test method begins." );
Thread.Sleep ( callDuration );
return "MyCallTime was " + callDuration.ToString ();
}
}
// The delegate must have the same signature as the method
// you want to call asynchronously.
public delegate string AsyncDelegate ( int callDuration );
public class AsyncMain
{
static void Main ( string[] args )
{
// Create an instance of the test class.
AsyncDemo ad = new AsyncDemo();
// Create the delegate.
AsyncDelegate dlgt = new AsyncDelegate ( ad.TestMethod );
// Initiate the asychronous call.
IAsyncResult ar = dlgt.BeginInvoke ( 3000, null, null );
Thread.Sleep ( 0 );
Console.WriteLine ( "Main thread does some work." );
// Call EndInvoke to Wait for the asynchronous call to complete,
// and to retrieve the results.
string ret = dlgt.EndInvoke ( ar );
Console.WriteLine("The call executed on thread with return value \"{0}\".",
ret);
Console.ReadLine ();
}
}
-Alex
>.
>