PC Review


Reply
Thread Tools Rate Thread

Call BeginInvoke on a Delegate

 
 
Thomas Lerchner
Guest
Posts: n/a
 
      10th Sep 2003
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 ();

}

}



 
Reply With Quote
 
 
 
 
Alex Yakhnin [eMVP]
Guest
Posts: n/a
 
      10th Sep 2003
AsyncDelegates are supported only in the few scenarios in
the current version of CF: Sockets and Async. calls to
WebServices.

-Alex

>-----Original Message-----
>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 ();
>
>}
>
>}
>
>
>
>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BeginInvoke on a delegate Bob Altman Microsoft VC .NET 9 29th Jul 2008 10:14 PM
Delegate BeginInvoke and ManualResetEvent.WaitOne() Alphapage Microsoft Dot NET Framework 6 15th Feb 2008 04:52 PM
BeginInvoke and anonymous delegate Dean Shimic Microsoft C# .NET 11 4th Sep 2006 08:56 PM
Control.BeginInvoke vs. delegate.BeginInvoke Valerie Hough Microsoft C# .NET 6 21st Oct 2005 11:14 AM
Cancelling a BeginInvoke on a delegate stand__sure Microsoft VB .NET 0 15th Jun 2005 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 PM.