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


C# BinaryOp.BeginInvoke方法代码示例

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


在下文中一共展示了BinaryOp.BeginInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: Main

 static void Main(string[] args)
 {
     Console.WriteLine("***** Async Delegate Invocation *****");
     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.");
     // using the member method or property of IAsyncResult
     // involve in Async process.
     //while (!iftAR.IsCompleted)
     //{
     //    Console.WriteLine("Doing more work in Main()");
     //    Thread.Sleep(1000);
     //}
     //while (!iftAR.AsyncWaitHandle.WaitOne(1000, true))
     //{
     //    Console.WriteLine("Doing more work in Main()");
     //}
     while (!isDone)
     {
         Thread.Sleep(1500);
         Console.WriteLine("Woring more work in Main()");
     }
     // 让第二个线程通知访问线程,当第二个线程的工作完成时。
     // 向BeginInvoke中传入AsyncCallback delegate,在BeginInvoke的异步调用结束时,
     // AsyncCallback委托会访问一个特殊的方法。
     // AsyncCallback委托的原型:     public delegate void AsyncCallback(IAsyncResult ar);
     //int answer = b.EndInvoke(iftAR);
     //Console.WriteLine("10 + 10 is {0}", answer);
     Console.WriteLine("Async work is complete!!");
     Console.ReadLine();
 }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:31,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            BinaryOp opCode = new BinaryOp(Add);
            Console.WriteLine("Threading!");
            Thread t = System.Threading.Thread.CurrentThread;
            Console.WriteLine(t.IsAlive);
            AppDomain ad = Thread.GetDomain();
            Console.WriteLine(ad.FriendlyName);
            System.Runtime.Remoting.Contexts.Context ctx = Thread.CurrentContext;

            Console.WriteLine("\nMain() thread id: {0}", Thread.CurrentThread.ManagedThreadId);
            //Console.WriteLine("waits till Add completes, delegate sum: {0}", opCode.Invoke(10, 30));
            //IAsyncResult iAsync = opCode.BeginInvoke(10, 50, null, null);
            //the called thread informs the primary thread that it hascompleted
            IAsyncResult iAsync = opCode.BeginInvoke(10, 50, new AsyncCallback(AddComplete), "author: naynish c");
            Console.WriteLine("Add called async");
            //keeps on asking if the call is complete
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            //waits for 200 milliseconds and asks if the call is complete
            iAsync.AsyncWaitHandle.WaitOne(200);
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            //Console.WriteLine("Sum: {0}", opCode.EndInvoke(iAsync));
            Console.WriteLine("Check if Add is complete {0}", iAsync.IsCompleted);
            ThreadProperties.Basics();
            Console.ReadLine();
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:26,代码来源:Program.cs

示例5: 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

示例6: Main

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

            BinaryOp b = new BinaryOp(Add);

            IAsyncResult iftAR = b.BeginInvoke(10, 10, new AsyncCallback(AddComplete), "custom state object");

            while (!isDone) {
                Thread.Sleep(1000);
                Console.WriteLine("-> Doing more work in main");
            }
            Console.WriteLine("Done...");
            Console.ReadLine();
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:15,代码来源:Program.cs

示例7: 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

示例8: Main

		public 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.");

			while (!isDone) 
			{
				Thread.Sleep(1000);
				Console.WriteLine("Working...");
			}
			Console.ReadLine();
		}
开发者ID:neziry,项目名称:Argeset,代码行数:16,代码来源:Main.cs

示例9: 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),
         "Thanks for this numbers.");
     // Assume other work is performed here...
     while (!isDone)
     {
         Thread.Sleep(1000);
         Console.WriteLine("Working....");
     }
     Console.ReadLine();
 }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:17,代码来源:Program.cs

示例10: 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

示例11: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Inside Main Method with Thread id :{0}",Thread.CurrentThread.ManagedThreadId);

            BinaryOp b = new BinaryOp(Add);
            //Stopwatch s = new Stopwatch();
            //s.Start();
            IAsyncResult res = b.BeginInvoke(10, 10, new AsyncCallback(AddComplete), "Main Thread says thanks to secondary thread for work");

            while (!isDone)
            {
                Console.WriteLine("Doing more work inside Main...");
                Thread.Sleep(1000);
            }
            
            //int result = b.EndInvoke(res);
            //Console.WriteLine("Answer is :{0} in {1} sec.",result,s.ElapsedMilliseconds/1000.0);
        }
开发者ID:mactavish2191,项目名称:Projects,代码行数:18,代码来源:Program.cs

示例12: 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

示例13: 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

示例14: Main

        static void Main(string[] args)
        {
            Console.WriteLine("***** AsyncCallbackDelegate Example *****");

            // 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 ift2 = b.BeginInvoke(20, 20, new AsyncCallback(AddComplete), "Main() thanks you for adding these numbers.");

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

            // Now we know the Add() method is complete.
            Console.ReadLine();
        }
开发者ID:JamesPinkard,项目名称:WalkthroughSolutions,代码行数:23,代码来源:Program.cs

示例15: 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


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