zoukankan      html  css  js  c++  java
  • 委托异步调用方法

            public delegate string CaptureHandler(string ip);
    
            public class CaptureService
            {
                public static string CapturePicture(string ip)
                {
                    Thread.Sleep(3000);
                    Console.WriteLine("work done part one");
                    return ip.ToString();
                }
            }
    
    
            static void Main(string[] args)
            {
                //Thread t = new Thread(new ParameterizedThreadStart(functionA));
                CaptureHandler handler = new CaptureHandler(CaptureService.CapturePicture);
    
                IAsyncResult result = handler.BeginInvoke("192.168.0.109", new AsyncCallback(SaveDb), handler);
                Console.WriteLine("main work continue");
    
                Console.ReadKey();
            }
    
            private static void SaveDb(IAsyncResult ar)
            {
                if (ar.IsCompleted)
                {
                    Console.WriteLine("work done part two");
                    var handler = ar.AsyncState as CaptureHandler;
                    var result = handler.EndInvoke(ar);
                    Console.WriteLine(result);
    
                }
                Console.WriteLine("ok");
            }
  • 相关阅读:
    CodeForces 834C
    HDU 6048
    HDU 6052
    HDU 6036
    HDU 6042
    HDU 2614 Beat(DFS)
    UESTC 1272 Final Pan's prime numbers(乱搞)
    HDU 2064 汉诺塔III(递归)
    HDU 2102 A计划(DFS)
    HDU 1069 I Think I Need a Houseboat(模拟)
  • 原文地址:https://www.cnblogs.com/tgdjw/p/5586602.html
Copyright © 2011-2022 走看看