zoukankan      html  css  js  c++  java
  • asynChronous delegaTes 异步委托 GIS

    static int TakesAWhile(int data, int ms)
    {
    Console.WriteLine("TakesAWhile started");
    Thread.Sleep(ms);
    Console.WriteLine("TakesAWhile completed");
    return ++data;
    }

    A simple way to create a thread is by defi ning a delegate and invoking the delegate asynchronously

    The delegate uses a thread pool for asynchronous tasks.

    public delegate int TakesAWhileDelegate(int data, int ms);

    static void Main()
    {
    // synchronous method call
    // TakesAWhile(1, 3000);
    // asynchronous by using a delegate
    TakesAWhileDelegate d1 = TakesAWhile;
    IAsyncResult ar = d1.BeginInvoke(1, 3000, null, null);
    while (!ar.IsCompleted)//如果委托线程没有完成
    {
    // doing something else in the main thread
    Console.Write(".");
    Thread.Sleep(50);
    }
    int result = d1.EndInvoke(ar);//结束委托线程
    Console.WriteLine("result: {0}", result);
    }

    .TakesAWhile started
    ..TakesAWhile completed
    result: 2

  • 相关阅读:
    【模板】并查集
    P1063能量项链
    多维动归第一题
    7.14测试
    7.12测试
    7.10测试
    几种display:table-cell的应用
    instanceof和typeof的区别
    右侧悬浮广告
    JavaScript判断浏览器类型及版本
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2588432.html
Copyright © 2011-2022 走看看