莫回无
public class A{ public string Test() => null; public void Main() { //方式1:TAP 异步模式 Task<string> task = Task.Run(new Func<string>(Test)); //做些别的事情...然后获取结果 task.Wait(); string result1 = task.Result; //方式2:APM 异步模式 Func<string> func = new Func<string>(Test); IAsyncResult asyncResult = func.BeginInvoke(null, null); //做些别的事情...然后获取结果 string result2 = func.EndInvoke(asyncResult); //方式3:线程 using (ManualResetEventSlim finishEvent = new ManualResetEventSlim(true)) { string tempResult = null; var thread = new Thread(() => { tempResult = Test(); finishEvent.Set(); }); thread.Start(); //做些别的事情...然后获取结果 finishEvent.Wait(); string result3 = tempResult; } }}