非UI线程的跨线程操作

研究silverlight异步调用方。

Silverlight中 非UI线程更新UI 的几种方法:Delegate, AsyncOperation,BackgroundWorker

1. delegate

void DoShow(i){ 
    this.Dispatcher.BeginInvoke( 
                            delegate { 
                                   txtCalc.Text = string.format(“result “{0}”,i); 
                            }); 
}

2.AsyncOperation

void DoShow(i){ 
    //这个可以写成成员变量,我这里只是为了好区分 
    System.ComponentModel.AsyncOperation asyncOper = System.ComponentModel.AsyncOperationManager.CreateOperation(null); 
    asyncOper.Post(result => 
            { 
                txtCalc.Text = string.format(“result “{0}”,i); 
            }, null); 
}

3.BackgroundWorker

 

posted @ 2011-04-28 08:52  huangliangjie  阅读(148)  评论(0编辑  收藏  举报