C#实践3task关键字

更新时间:2023-05-28 04:40:42 阅读: 评论:0

C#实践3task关键字参考:clusters
“ 类表⽰不返回值并且通常以异步⽅式执⾏的单个操作”
来⾃参考的⽰例代码:
using System;
using System.Threading;
using System.Threading.Tasks;
class Example
{
static void Main()
wolf是什么意思{
Action<object> action = (object obj) =>四级听力真题
{
Console.WriteLine("Task={0}, obj={1}, Thread={2}",
Task.CurrentId, obj,
Thread.CurrentThread.ManagedThreadId);
};
// Create a task but do not start it.
Task t1 = new Task(action, "alpha");克莱尔丹尼斯
接受的英文// Construct a started task
Task t2 = Task.Factory.StartNew(action, "beta");
// Block the main thread to demonstrate that t2 is executing
t2.Wait();该死的英文
/
/ Launch t1
女孩英语名字t1.Start();
Console.WriteLine("t1 has been launched. (Main Thread={0})",
Thread.CurrentThread.ManagedThreadId);
// Wait for the task to finish.
t1.Wait();成都英语夏令营
// Construct a started task using Task.Run.
String taskData = "delta";
Task t3 = Task.Run( () => {Console.WriteLine("Task={0}, obj={1}, Thread={2}",
Task.CurrentId, taskData,
Thread.CurrentThread.ManagedThreadId);
});
英语小对话// Wait for the task to finish.
t3.Wait();
// Construct an unstarted task
Task t4 = new Task(action, "gamma");
// Run it synchronously
t4.RunSynchronously();
// Although the task was run synchronously, it is a good practice
// to wait for it in the event exceptions were thrown by the task.
t4.Wait();
}
}
// The example displays output like the following:
//      Task=1, obj=beta, Thread=3
//      t1 has been launched. (Main Thread=1)
//      Task=2, obj=alpha, Thread=4
gracenote//      Task=3, obj=delta, Thread=3
//      Task=4, obj=gamma, Thread=1

本文发布于:2023-05-28 04:40:42,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/797113.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:参考   返回值   真题   女孩   类表   听力
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图