public static void Main() { AsyncCaller ac = new AsyncCaller(); ac.CallMathCallback(new AsyncCaller.MathFunctionToCall(DoCalculation)); //Thread.Sleep(500); // no longer needed }
public static void Main() { AsyncCaller ac = new AsyncCaller(); ac.CallMathCallback(new AsyncCaller.MathFunctionToCall(Math.Sin), 0.0, 1.0, 0.2); Thread.Sleep(2000); }
public static void FooCallBack(IAsyncResult ar) { PrintCurrThreadInfo("FooCallBack()"); AsyncCaller caller = (AsyncCaller)ar.AsyncState; caller.EndInvoke(ar); }
public void AsyncCallerWorks() { var handler = new EventHandler((sender, args) => Thread.Sleep(500)); var caller = new AsyncCaller(handler); Assert.IsTrue(caller.Invoke(1000, null, EventArgs.Empty)); Assert.IsFalse(caller.Invoke(300, null, EventArgs.Empty)); }
public static void Main() { AsyncCaller ac = new AsyncCaller(); ac.CallWriteLineWithCallback("Hello There"); System.Threading.Thread.Sleep(1000); }
public void ReadCache(float position) { AsyncCaller asynctask = new AsyncCaller(filemanager.ReadGPSCache); IAsyncResult asyncresult = asynctask.BeginInvoke(position, null, null); CacheData2 = asynctask.EndInvoke(asyncresult); reading = false; returned = true; }
void GetResultsCallback(IAsyncResult result) { //result.AsyncState as AsyncCaller; AsyncCaller asyncDelegate = result.AsyncState as AsyncCaller;//(AsyncCaller)((AsyncResult)result).AsyncDelegate; if (asyncDelegate != null) { asyncDelegate.EndInvoke(out m_output, result); } m_waiter.Set(); }
public void Invoke_6000_ReturnFalse() { //arrange var h = new EventHandler((sender, args) => Thread.Sleep(6000)); var ac = new AsyncCaller(h); //act bool completedOK = ac.Invoke(5000, null, EventArgs.Empty); //assert Assert.IsFalse(completedOK); }
static void Main(string[] args) { EventHandler h = new EventHandler(MyEventHandler); AsyncCaller ac = new AsyncCaller(h); Console.WriteLine("\ntime limit: 1000 ms: "); bool completedOK = ac.Invoke(1000, null, EventArgs.Empty); Console.WriteLine("\ntime limit: 5000 ms: "); completedOK = ac.Invoke(5000, null, EventArgs.Empty); Console.Write("\nPress any key.."); Console.ReadKey(); }
public bool StartAsynchronousCall(AsyncCaller caller, Object input) { m_output = null; AsyncCaller callDelegate = new AsyncCaller(caller); // Asynchronously invoke the Factorize method. Object output = null; AsyncCallback callBack = new AsyncCallback(this.GetResultsCallback); //Object temp = null; IAsyncResult result = callDelegate.BeginInvoke( input, out output, callBack, callDelegate); return(true); }
static void Main(string[] args) { EventHandler h = new EventHandler(MyEventHandler); IAsyncCaller ac = new AsyncCaller(h); Enumerable.Range(0, 2) .Select(r => 2000 + r * 3000) .ToList() .ForEach(timeout => { Console.WriteLine($"\nTime limit: {timeout} ms: "); bool completedOK = ac.Invoke(timeout, null, EventArgs.Empty); Console.WriteLine(completedOK ? "\nOperation finished successfully." : $"\nOperation was canceled by time limit: {timeout} ms."); }); Console.Write("\nPress any key.."); Console.ReadKey(); }
public static void Main() { AsyncCaller ac = new AsyncCaller(); ac.CallMathCallback(new AsyncCaller.MathFunctionToCall(DoCalculation)); }
public static void PostAsyc() { AsyncCaller caller = new AsyncCaller(Foo); caller.BeginInvoke(1000, new AsyncCallback(FooCallBack), caller); }
public string EndIntToString(IAsyncResult ar) { AsyncCaller caller = ((AsyncResult)ar).AsyncDelegate as AsyncCaller; return(caller.EndInvoke(ar)); }
public IAsyncResult BeginIntToString(int integer, AsyncCallback callback = null) { AsyncCaller caller = new AsyncCaller(IntToString); return(caller.BeginInvoke(integer, callback, this)); }
public static void Main() { AsyncCaller ac = new AsyncCaller(); ac.CallWriteLine("Hello"); }