Exemplo n.º 1
0
    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);
    }
Exemplo n.º 3
0
        public static void FooCallBack(IAsyncResult ar)
        {
            PrintCurrThreadInfo("FooCallBack()");
            AsyncCaller caller = (AsyncCaller)ar.AsyncState;

            caller.EndInvoke(ar);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
    public static void Main()
    {
        AsyncCaller ac = new AsyncCaller();

        ac.CallWriteLineWithCallback("Hello There");

        System.Threading.Thread.Sleep(1000);
    }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
    public static void Main()
    {
        AsyncCaller ac = new AsyncCaller();

        ac.CallMathCallback(new AsyncCaller.MathFunctionToCall(DoCalculation));
    }
Exemplo n.º 13
0
 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;
 }
Exemplo n.º 14
0
        public static void PostAsyc()
        {
            AsyncCaller caller = new AsyncCaller(Foo);

            caller.BeginInvoke(1000, new AsyncCallback(FooCallBack), caller);
        }
Exemplo n.º 15
0
        public string EndIntToString(IAsyncResult ar)
        {
            AsyncCaller caller = ((AsyncResult)ar).AsyncDelegate as AsyncCaller;

            return(caller.EndInvoke(ar));
        }
Exemplo n.º 16
0
        public IAsyncResult BeginIntToString(int integer, AsyncCallback callback = null)
        {
            AsyncCaller caller = new AsyncCaller(IntToString);

            return(caller.BeginInvoke(integer, callback, this));
        }
Exemplo n.º 17
0
    public static void Main()
    {
        AsyncCaller ac = new AsyncCaller();

        ac.CallWriteLine("Hello");
    }