当前位置: 移动技术网 > IT编程>开发语言>.net > WPF 小小案列(同步异步)

WPF 小小案列(同步异步)

2019年04月16日  | 移动技术网IT编程  | 我要评论

香港黄金价,海影阁,市盈率如何计算

private void btnbutton_click(object sender, routedeventargs e)
{
messagebox.show("hello word");
}
private void modifyui()
{
// 模拟一些工作正在进行
thread.sleep(timespan.fromseconds(2));
//lblhello.content = "欢迎你光临wpf的世界,dispatcher";
this.dispatcher.invoke(dispatcherpriority.normal, (threadstart)delegate ()
{
lblhello.content = "欢迎你光临wpf的世界,dispatche 同步方法 !!"+datetime.now.tostring();
messagebox.show("你好我是多线程同步方法");
});
}

private void btnthd_click(object sender, routedeventargs e)
{
thread thread = new thread(modifyui);
thread.start();
}
/// <summary>
/// 异步方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnappbegininvoke_click(object sender, routedeventargs e)
{
new thread(() =>
{
application.current.dispatcher.begininvoke(dispatcherpriority.normal,
new action(() =>
{
thread.sleep(timespan.fromseconds(2));

this.lblhello.content = "欢迎你光临wpf的世界,dispatche 异步方法!!" + datetime.now.tostring();
messagebox.show("你好我是多线程异步方法");
}));
}).start();
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网