国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湟中县| 杂多县| 资阳市| 通化县| 韶关市| 奉化市| 于都县| 石家庄市| 黄骅市| 炎陵县| 图木舒克市| 皋兰县| 桐庐县| 汤阴县| 女性| 阜新市| 若尔盖县| 永登县| 靖江市| 阳原县| 甘泉县| 甘南县| 肃南| 佛坪县| 廉江市| 探索| 平和县| 宜良县| 广宗县| 烟台市| 天等县| 贡嘎县| 察隅县| 丹棱县| 黄平县| 江西省| 云南省| 大港区| 会泽县| 海丰县| 乐陵市|