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

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

        ac.CallWriteLineWithCallback("Hello There");

        System.Threading.Thread.Sleep(1000);
    }
Exemple #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;
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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();
        }
Exemple #12
0
    public static void Main()
    {
        AsyncCaller ac = new AsyncCaller();

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

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

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

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

        ac.CallWriteLine("Hello");
    }