当前位置:网站首页>Record how to modify the control across threads
Record how to modify the control across threads
2022-06-26 05:51:00 【self85】
Talk is cheap, Show you the code first!
private async void Form1_Load(object sender, EventArgs e)
{
var t = Task.Run(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(2));
return "hello";
});
lb.Text = await t;
timer1.Enabled = true;
timer1.Interval = 2000;
}
private async void timer1_Tick(object sender, EventArgs e)
{
var t = Task.Run(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(5));
return string.Format("{0:U}", DateTime.Now);
});
lb.Text = await t;
}

Hint await Its function is to split ,await Before and after, it will be processed in two threads .
For specific articles, please refer to
C# Understand thoroughly async/await - Five dimensional thinking - Blog Garden
https://www.cnblogs.com/zhaoshujie/p/11192036.html
边栏推荐
- [C language] deep analysis of data storage in memory
- About abstact and virtual
- BOM文档
- 力扣 875. 爱吃香蕉的珂珂
- A love that never leaves
- Customize WebService as a proxy to solve the problem of Silverlight calling WebService across domains
- Daily production training report (17)
- Sql查询时间段内容
- 从新东方直播来探究下小程序音视频通话及互动直播
- Data storage: the difference between MySQL InnoDB and MyISAM
猜你喜欢

Uni app ceiling fixed style

电商借助小程序技术发力寻找增长突破口

423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)
从新东方直播来探究下小程序音视频通话及互动直播

小程序如何关联微信小程序二维码,实现二码聚合

家庭记账程序(第一版)

Implementation of third-party wechat authorized login for applet

家庭记账程序(第二版 加入了循环)

冒泡排序(Bubble Sort)
![Operator priority, associativity, and whether to control the evaluation order [detailed explanation]](/img/c3/a646a7c7cb82e00746923f7b023058.jpg)
Operator priority, associativity, and whether to control the evaluation order [detailed explanation]
随机推荐
Household accounting procedures (First Edition)
Gram 矩阵
项目中止
Customize WebService as a proxy to solve the problem of Silverlight calling WebService across domains
cross entropy loss = log softmax + nll loss
Gram matrix
5 minutes to learn regular expressions
RIA想法
解决在win10下cmder无法使用find命令
Security problems in wireless networks and modern solutions
最后一次飞翔
Could not get unknown property ‘*‘ for SigningConfig container of type org. gradle. api. internal
Machine learning 05: nonlinear support vector machines
Kolla ansible deploy openstack Yoga version
组合模式、透明方式和安全方式
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
Daily production training report (15)
通俗易懂的从IDE说起,再谈谈小程序IDE
Last flight
Lesson 4 serial port and clock