zoukankan      html  css  js  c++  java
  • 4.5 异步特性 无觉

           private async void StartButton_Click(object sender, RoutedEventArgs e)
            {
                // ExampleMethodAsync returns a Task<int> and has an int result.
                // A value is assigned to intTask when ExampleMethodAsync reaches
                // an await.
                try
                {
                    Task<int> intTask = ExampleMethodAsync();
                    // You can do other work here that doesn't require the result from
                    // ExampleMethodAsync. . . .
                    // You can access the int result when ExampleMethodAsync completes.
                    int intResult = await intTask;
    
                    // Or you can combine the previous two steps:
                    //int intResult = await ExampleMethodAsync();
    
                    // Process the result (intResult). . . .
                }
                catch (Exception)
                {
                    // Process the exception. . . .
                }
            }
    
            public async Task<int> ExampleMethodAsync()
            {
                var httpClient = new HttpClient();
    
                // At the await expression, execution in this method is suspended, and
                // control returns to the caller of ExampleMethodAsync.
                // Variable exampleInt is assigned a value when GetStringAsync completes.
                int exampleInt = (await httpClient.GetStringAsync("http://msdn.microsoft.com")).Length;
    
                // You can break the previous line into several steps to clarify what happens:
                //Task<string> contentsTask = httpClient.GetStringAsync("http://msdn.microsoft.com");
                //string contents = await contentsTask;
                //int exampleInt = contents.Length; 
    
                // Continue with whatever processing is waiting for exampleInt. . . .
    
                // After the return statement, any method that's awaiting
                // ExampleMethodAsync can get the integer result.
                return exampleInt;
            }
  • 相关阅读:
    PHP常用字符串函数
    PHP 中解析 url 并得到 url 参数
    PHP中的10个实用函数
    虚拟主机知识全解
    php三种常用的加密解密算法
    Javascript中的位运算符和技巧
    ECMAScript 5中新增的数组方法
    捕捉小括号获取的内容保存在RegExp的$1 $2..属性中
    js获取浏览器窗口的大小
    关于switch的思考和总结
  • 原文地址:https://www.cnblogs.com/LiMin/p/2997175.html
Copyright © 2011-2022 走看看