国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

簡單介紹.Net3.0中跨線程訪問控件

2019-11-14 14:28:46
字體:
來源:轉載
供稿:網友

這兩天用WPF做一個項目的UI部分時,發現跨線程地訪問了UI控件,自然地報異常了。當時找了半天也沒在控件中找到InvokeRequired屬性和Invoke方法,郁悶之極.....最后發現在.net3.0中,這有所改變了。

  替代InvokeRequired的方法是DispatcherObject.Checkaccess()或DispatcherObject.VerifyAccess()方法,用于指示當前線程是否可以直接訪問控件。

  替代Invoke的方法是DispatcherObject.Dispatcher.BeginInvoke(...)方法。

  參考代碼:

 

  // Uses the DispatcherObject.CheckAccess method to determine if 
  // the calling thread has access to the thread the UI object is on 
  PRivate void TryToUpdateButtonCheckAccess(object uiObject) 
  { 
   Button theButton = uiObject as Button; 
   
   if (theButton != null) 
   { 
   // Checking if this thread has access to the object 
   if(theButton.CheckAccess()) 
   { 
   // This thread has access so it can update the UI thread 
   UpdateButtonUI(theButton); 
   } 
   else 
   { 
   // This thread does not have access to the UI thread 
   // Pushing update method on the Dispatcher of the UI thread 
   theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, 
   new UpdateUIDelegate(UpdateButtonUI), theButton); 
   } 
   } 
  }
轉載自:http://www.aspnetjia.com/Cont-172.html

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉门市| 上思县| 孟连| 盐津县| 石楼县| 广水市| 淮北市| 郸城县| 乐都县| 上杭县| 青铜峡市| 洪湖市| 贵定县| 维西| 吴旗县| 屏山县| 连平县| 芮城县| 吴堡县| 宁远县| 永德县| 抚远县| 来凤县| 县级市| 晋城| 新乐市| 高尔夫| 承德县| 玉环县| 通河县| 六安市| 大港区| 定西市| 郁南县| 潜江市| 留坝县| 金沙县| 沙湾县| 平凉市| 都匀市| 武隆县|