日期:2014-05-17 浏览次数:20995 次
private AsyncOperation asyncOpr;
this.asyncOpr = AsyncOperationManager.CreateOperation(null);
Task.Factory.StartNew(() => this.读取数据()).ContinueWith(c =>
{
if (c.IsCompleted)
{
this.asyncOpr.Post(obj =>
{
//在些将数据绑定到控件
}, null);
}
if (c.Exception != null)
{
//异常处理
MessageBox.Show(c.Exception.Message);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
MSG msg;
while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem((o) => {
ComboBox cbb = new ComboBox();
for (int i = 0; i < 30000; i++)