Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call BeginInvoke on a Delegate

3 views
Skip to first unread message

Thomas Lerchner

unread,
Sep 10, 2003, 8:04:54 AM9/10/03
to
Hi!

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 Yakhnin [eMVP]

unread,
Sep 10, 2003, 8:38:39 AM9/10/03
to
AsyncDelegates are supported only in the few scenarios in
the current version of CF: Sockets and Async. calls to
WebServices.

-Alex

>.
>

0 new messages