https://msdn.microsoft.com/zh-cn/library/wewwczdw(v=vs.110).aspx Applications that perform many tasks simultaneously, yet remain responsive to user interaction, often require a design that uses multiple threads. 同时执行多项任务,并且仍要相应用户交互的应用,通常需要一个使用多线程的设计.…
using System; using System.Threading; using System.Threading.Tasks; using static System.Console; //异步编程 //1.异步模式 //2.基于事件的异步模式 //3.基于任务的异步模式 namespace ConsoleApp { class Program { public static void TaskMethod(object o) { Log(o?.ToString()); } privat…
对于窗体程序,使用基于任务的异步模式需要用到Task类,下面示例下非常简单的用法. 1.创建一个拥有异步方法的类 该类拥有一个异步方法DoSomthingAsync,根据微软建议的命名规则该方法要带Async后缀 public class Dog { public Task DoSomthingAsync() { Task task = Task.Run(() => { Console.WriteLine("后台任务开始运行"); Thread.Sleep(); Console.…