c#子线程操作ui
2015-11-30 20:47
381 查看
子线程本是不能操作ui数据的,但有时候需要更新ui的数据。
// 声明
WindowsFormsSynchronizationContext _syncContext = WindowsFormsSynchronizationContext.Current as WindowsFormsSynchronizationContext;
//调用
_syncContext.Post(Func, null);
// 函数
private void Func(object obj)
{
// do something
}
// 线程
Thread thread = new Thread(TaskStop);
thread.Start();
// 任务
Task task = new Task(TaskStop);
task.Start();
// 声明
WindowsFormsSynchronizationContext _syncContext = WindowsFormsSynchronizationContext.Current as WindowsFormsSynchronizationContext;
//调用
_syncContext.Post(Func, null);
// 函数
private void Func(object obj)
{
// do something
}
// 线程
Thread thread = new Thread(TaskStop);
thread.Start();
// 任务
Task task = new Task(TaskStop);
task.Start();
相关文章推荐
- 让IE8支持@media query
- UITableView
- 《算法竞赛入门经典2ndEdition 》例题3-6 环状序列(Circular Sequence, Uva1584)
- C# 使用msbuild编译程序
- scala剖析PriorityQueue,权值的使用
- 安装UIIamge拾取图片插件
- 【Win10开发】绘制静态UI
- UI-1-UI入门
- MyEclips启动报错:'Building workspace' has encountered a problem的解决方法
- UI基础-UI高级 可视化设计
- layout_centerVertical="true"用法
- 35.UITabBarController(标签视图控制器)
- 大鱼吃小鱼游戏-fruit.js
- XCTest/XCTest.h not found on old projects built in Xcode
- UI基础
- IOS之--UI进阶--多控制器管理第一天
- easygui(一)
- RabbitMQ 入门三(Work Queues)
- Orcle 主键自增(序列sequence、触发器trigger、主键primary)
- building and installing openCV3 with extra modules on VS2013 win8