当前位置: 首页>>代码示例>>C#>>正文


C# BinaryOp.EndInvoke方法代码示例

本文整理汇总了C#中BinaryOp.EndInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryOp.EndInvoke方法的具体用法?C# BinaryOp.EndInvoke怎么用?C# BinaryOp.EndInvoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryOp的用法示例。


在下文中一共展示了BinaryOp.EndInvoke方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Console.WriteLine("***** Async Delegate Invocation *****");

            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
              Thread.CurrentThread.ManagedThreadId);

            BinaryOp b = new BinaryOp(Add);
            IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);

            // This message will keep printing until
            // the Add() method is finished.
            while (!iftAR.IsCompleted)
            {
                Console.WriteLine("Doing more work in Main()!");
                Thread.Sleep(1000);
            }

            // Now we know the Add() method is complete.
            int answer = b.EndInvoke(iftAR);

            Console.WriteLine("10 + 10 is {0}.", answer);
            Console.ReadLine();
        }
开发者ID:usedflax,项目名称:flaxbox,代码行数:25,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            Console.WriteLine("*****  AsyncCallbackDelegate Example *****");
              Console.WriteLine("Main() invoked on thread {0}.",
            Thread.CurrentThread.ManagedThreadId);

              BinaryOp b = new BinaryOp(Add);
              IAsyncResult iftAR = b.BeginInvoke(10, 10,
            new AsyncCallback(AddComplete),
            "Main() thanks you for adding these numbers.");

              // Assume other work is performed here...
              while (!isDone)
              {
            Thread.Sleep(1000);
            Console.WriteLine("Working....");
              }

              // BeginInvoke / EndInvoke
              IAsyncResult asyncResult = b.BeginInvoke(8, 7, null, null);
              int result1 = b.EndInvoke(asyncResult);
              Console.WriteLine("{0}", result1);

              // System.Threading.Tasks.Task
              Task task = null;
              task = Task.Factory.StartNew(() =>
              {
              b.BeginInvoke(9, 9, null, null);
              int result2 = b.EndInvoke(asyncResult);
              Console.WriteLine("{0}", result2);
              });

              while (task.Status == TaskStatus.Running)
              {
            // wait
              }

              // System.Threading.Tasks.Parallel
              Parallel.Invoke(() => Add(3, 4), () => Add(3, 4), () => Add(3, 4));

              Console.ReadLine();
        }
开发者ID:babelfish42,项目名称:dotNet,代码行数:42,代码来源:Program.cs

示例3: AsyncDelegate

 public static void AsyncDelegate()
 {
     Console.WriteLine("AsyncDelegate() on thread Id: {0}", Thread.CurrentThread.ManagedThreadId);
     BinaryOp b = new BinaryOp(Add);
     IAsyncResult iar = b.BeginInvoke(1, 2, null, null);
     //while (!iar.IsCompleted) {
     //    Console.WriteLine("doing more foreground work...");
     //    Thread.Sleep(1000);
     //}
     while (!iar.AsyncWaitHandle.WaitOne(1000, true)) {
         Console.WriteLine("doing more foreground work...");
     }
     int z = b.EndInvoke(iar);
     Console.WriteLine("AsyncDelegate() z = {0}", z);
 }
开发者ID:walrus7521,项目名称:code,代码行数:15,代码来源:Thread.cs

示例4: AsyncCall

        static void AsyncCall()
        {
            Console.WriteLine("***** Async Delegate Review *****");
            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
            Thread.CurrentThread.ManagedThreadId);
            // Invoke Add() in a asynchronous manner.
            // but it is still synchronous call.
            BinaryOp b = new BinaryOp(Add);

            IAsyncResult res = b.BeginInvoke(10, 10, null, null);

            Console.WriteLine("Doing more work in Main()!");

            //Obtain results from Add
            int answer = b.EndInvoke(res);
            Console.WriteLine("10 + 10 is {0}.", answer);
        }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:18,代码来源:Program.cs

示例5: Main

		public static void Main (string[] args)
		{
			Console.WriteLine ("** Sync Delegate Review **");

			Console.WriteLine ("Main() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);

			BinaryOp b = new BinaryOp (Add);
			IAsyncResult iftAR = b.BeginInvoke (10, 10, null, null);
//			int answer = b(10, 10);

			while (!iftAR.IsCompleted) 
			{			
				Console.WriteLine("Doing more work in Main()");
				Thread.Sleep(1000);
			}
			int answer = b.EndInvoke(iftAR);
//			Console.WriteLine("Doing more work in main()");
			Console.WriteLine("10 + 10 is {0}", answer);
			Console.ReadLine();
		}
开发者ID:neziry,项目名称:Argeset,代码行数:20,代码来源:Main.cs

示例6: Main

        static void Main(string[] args)
        {
            Console.WriteLine("***** Async Delegate Invocation *****");

            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
            Thread.CurrentThread.ManagedThreadId);

            // Invoke Add() on a secondary thread.
            BinaryOp b = new BinaryOp(Add);
            IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);

            // Do other work on primary thread...
            Console.WriteLine("Doing more work in Main()!");

            // Obtain the result of the Add()
            // method when ready.
            int answer = b.EndInvoke(iftAR);
            Console.WriteLine("10 + 10 is {0}.", answer);
            Console.ReadLine();
        }
开发者ID:justasabc,项目名称:csharp_tutorials,代码行数:21,代码来源:Program.cs

示例7: UseBeginInvoke

 private void UseBeginInvoke(BinaryOp binOp, int x, int y)
 {
     IAsyncResult asyncRes = binOp.BeginInvoke(x, y, null, null);
     //RunWaitHandle(asyncRes);
     RunIsCompletedCall(asyncRes);
     int answer = binOp.EndInvoke(asyncRes);
     Console.WriteLine("{0} + {1} = {2}", x, y, answer);
 }
开发者ID:ghostmonk,项目名称:CSharpTutorials,代码行数:8,代码来源:BinaryOperation.cs

示例8: AsyncTest

        private static void AsyncTest()
        {
            Console.WriteLine("***** Async Delegate Review");
            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);

            // Invoke Add() in a secondary thread.
            BinaryOp b = new BinaryOp(Add);
            IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);

            // Do other work on primary thread..
            // This call takes far less than five seconds
            // because of async
            while (!iftAR.AsyncWaitHandle.WaitOne(1000,true))
            {
                Console.WriteLine("Doing more word in Main()!");
            }
            // Obtain the result of the Add();
            // Now we are waiting again for other thread to compelte
            int answer = b.EndInvoke(iftAR);
            Console.WriteLine("10 + 10 is {0}", answer);
            Console.ReadLine();
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:23,代码来源:Program.cs

示例9: WaitCall

        static void WaitCall()
        {
            Console.WriteLine("***** Async Delegate Review *****");
            // Print out the ID of the executing thread.
            Console.WriteLine("Main() invoked on thread {0}.",
            Thread.CurrentThread.ManagedThreadId);
            // Invoke Add() in a asynchronous manner.
            BinaryOp b = new BinaryOp(Add);

            IAsyncResult res = b.BeginInvoke(10, 10, null, null);

            //while (!res.IsCompleted)
            //{
            //    Console.WriteLine("Doing more work in Main()!");
            //    Thread.Sleep(1000);
            //}
            while (!res.AsyncWaitHandle.WaitOne(1000, true))
            {
                Console.WriteLine("Doing more work in Main()!");
            }

            //Obtain results from Add
            int answer = b.EndInvoke(res);
            Console.WriteLine("10 + 10 is {0}.", answer);
        }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:25,代码来源:Program.cs


注:本文中的BinaryOp.EndInvoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。