国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 丹阳市| 织金县| 故城县| 苍溪县| 油尖旺区| 博乐市| 舞钢市| 墨竹工卡县| 厦门市| 石门县| 台中县| 临沭县| 长丰县| 抚州市| 乌拉特后旗| 通州市| 邮箱| 临桂县| 宜州市| 黄浦区| 荔波县| 沐川县| 洪雅县| 财经| 华安县| 鄱阳县| 云安县| 韩城市| 巴青县| 永宁县| 三原县| 张家界市| 湟中县| 宝兴县| 新疆| 武鸣县| 神木县| 黄陵县| 雅安市| 娄底市| 东阿县|