相关疑难解决方法(0)

C#-Four模式在异步执行中

我听说异步执行有四种模式.

"异步委托执行有四种模式:轮询,等待完成,完成通知和"消防和忘记".

当我有以下代码时:

class AsynchronousDemo
{
    public static int numberofFeets = 0;
    public delegate long StatisticalData();

    static void Main()
    {
        StatisticalData data = ClimbSmallHill;
        IAsyncResult ar = data.BeginInvoke(null, null);
        while (!ar.IsCompleted)
        {
            Console.WriteLine("...Climbing yet to be completed.....");
            Thread.Sleep(200);

        }
        Console.WriteLine("..Climbing is completed...");
        Console.WriteLine("... Time Taken for  climbing ....{0}", 
        data.EndInvoke(ar).ToString()+"..Seconds");
        Console.ReadKey(true);

    }


    static long ClimbSmallHill()
    {
        var sw = Stopwatch.StartNew();
        while (numberofFeets <= 10000)
        {
            numberofFeets = numberofFeets + 100;
            Thread.Sleep(10);
        }
        sw.Stop();
        return sw.ElapsedMilliseconds;
    }
}
Run Code Online (Sandbox Code Playgroud)

1)上述代码实现的模式是什么?

2)你能解释一下代码,我该如何实现其余的代码?

c# asynchronous execution

41
推荐指数
1
解决办法
4万
查看次数

标签 统计

asynchronous ×1

c# ×1

execution ×1