using System;
using System.Collections.Generic;
using System.Text;
using InTheHand.Net;
using System.Threading;
namespace ConsoleMenuTesting{
class DelegateExtension
{
public static IAsyncResult BeginInvoke<T>(/*this*/ Action<T> dlgt,
T obj, AsyncCallback callback, object @object)
{
AsyncResultNoResult ar = new AsyncResultNoResult(callback, @object);
WaitCallback dlgt2 = delegate {
try {
dlgt(obj);
ar.SetAsCompleted(null, false);
} catch (Exception ex) {
ar.SetAsCompleted(ex, false);
}
};
ThreadPool.QueueUserWorkItem(dlgt2);
return ar;
}
public static void EndInvoke<T>(/*this*/ Action<T> dlgt, IAsyncResult ar)
{
AsyncResultNoResult ar2 = (AsyncResultNoResult)ar;
ar2.EndInvoke();
}
}
}
|