关于PrintQueueCollection()类,跨线程调用错误“线程无法访问此对象,因为另一个线程拥有该对象”
生活随笔
收集整理的這篇文章主要介紹了
关于PrintQueueCollection()类,跨线程调用错误“线程无法访问此对象,因为另一个线程拥有该对象”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用System.Printing.PrintQueueCollection() ??紙質打印機獲取
_generalPrinters = new PrintQueueCollection();
? ? ? ? public PrintQueueCollection GeneralPrinters
? ? ? ? {
? ? ? ? ? ? get { return _generalPrinters; }
? ? ? ? ? ? set { _generalPrinters = value; }
? ? ? ? }
GeneralPrinters是不允許跨線程調用的。
偶現會提示:“線程無法訪問此對象,因為另一個線程擁有該對象”
根源:
PrintQueueCollection 類的構造中有這樣一行:
this.accessVerifier = new PrintSystemDispatcherObject();
所以PrintQueueCollection僅其創建線程可用
跨線程調用,需要PrintQueueCollection()新線程重新調用。
總結
以上是生活随笔為你收集整理的关于PrintQueueCollection()类,跨线程调用错误“线程无法访问此对象,因为另一个线程拥有该对象”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS2012 快捷键 VS RESHAR
- 下一篇: 预编译头超出上限错误 就是include