[Mono-list] delegates and AsyncCallback

Dietmar Maurer dietmar@ximian.com
18 Mar 2002 18:26:45 +0100


I just try to implement asynchronous delegate support, but I don't know
when to invoke the AsyncCallback passed to BeginInvoke:

a.) just before leaving BeginInvoke
b.) before we actually run the method
c.) when the method finished

On MS the callback is only called sometimes - don't know what I am doing
wrong. Any suggestions?

- Dietmar


using System;
using System.Runtime.InteropServices;

namespace Bah {
class Test {
	delegate int SimpleDelegate (int a);

	static int F (int a) {
		Console.WriteLine ("Test.F from delegate: " + a);
		return a;
	}

	static void async_callback (IAsyncResult ar)
	{
		Console.WriteLine ("Async Callback");
	}
	
	static int Main () {
		SimpleDelegate d = new SimpleDelegate (F);
		AsyncCallback ac = new AsyncCallback (async_callback);
		string state = "STATE OBJECT";
		
		IAsyncResult ar = d.BeginInvoke (3, ac, state);
		
		d.EndInvoke (ar);
		
		return 0;
	}
}
}