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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

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

2019-11-14 14:18:33
字體:
供稿:網(wǎng)友

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

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

  替代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); 
   } 
   } 
  }
轉(zhuǎn)載自:http://www.aspnetjia.com/Cont-172.html

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 依安县| 广饶县| 色达县| 汉川市| 沾益县| 中山市| 建瓯市| 延川县| 竹山县| 吴川市| 离岛区| 城口县| 汉阴县| 九台市| 邵阳县| 九江市| 手机| 澳门| 泽州县| 陇南市| 安岳县| 西青区| 桓台县| 奉贤区| 莫力| 民县| 纳雍县| 科技| 南木林县| 阿巴嘎旗| 红桥区| 利津县| 房山区| 化德县| 游戏| 吉安市| 米林县| 筠连县| 阿克苏市| 凤冈县| 鸡泽县|