Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Process p1 = new Process();
            Process p2 = new Process();
            Process p3 = new Process();
            DateTime now = DateTime.Now;

            DoItDelegate doIt1 = new DoItDelegate(p1.DoIt);
            DoItDelegate doIt2 = new DoItDelegate(p2.DoIt);
            DoItDelegate doIt3 = new DoItDelegate(p3.DoIt);

            IAsyncResult result1 = doIt1.BeginInvoke(null, null);
            IAsyncResult result2 = doIt2.BeginInvoke(null, null);
            IAsyncResult result3 = doIt3.BeginInvoke(null, null);

            WaitHandle.WaitAll(new WaitHandle[] { result1.AsyncWaitHandle, result2.AsyncWaitHandle, result3.AsyncWaitHandle });

            int one = doIt1.EndInvoke(result1);
            int two = doIt2.EndInvoke(result2);
            int three = doIt3.EndInvoke(result3);

            Console.WriteLine("DoIt Total Time: {0}", one + two + three);

            //int x = p1.DoIt();
            //int y = p2.DoIt();
            //int z = p3.DoIt();
            //Console.WriteLine("DoIt Total Time: {0}", x + y + z);

            Console.WriteLine("Program Total time: {0}", (DateTime.Now - now).TotalMilliseconds);
            Console.ReadLine();
        }
Exemplo n.º 2
0
 public DelegateTask(string name, int interval, DoItDelegate dlg, object w)
 {
     Name      = name;
     _interval = interval;
     _what     = w;
     _whatToDo = dlg;
 }
Exemplo n.º 3
0
    public void DoItAsync(string[] args)
    {
        DoItDelegate doIt = this.DoIt;

        doIt.BeginInvoke(args, this.DoDoItCompleted, doIt);
    }
Exemplo n.º 4
0
 protected void SetDelegate(DoItDelegate dlg)
 {
     _whatToDo = dlg;
 }