我很困惑這實際上是如何實現的。當從ClipBoard中獲取數據時發生死鎖(GetDataObject)
在我的應用程序(.NET Framework 4.0中)我有一個 「粘貼」 按鈕。在應用程序啓動時或焦點對象更改時,我會檢查剪貼板中的數據以設置該按鈕的啓用狀態。
現在,它的發生幾次(一臺機器上),這個功能似乎死鎖。看看堆棧跟蹤:
at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags)
at System.Windows.Forms.UnsafeNativeMethods.OleGetClipboard(IDataObject& data)
at System.Windows.Forms.Clipboard.GetDataObject(Int32 retryTimes, Int32 retryDelay)
at System.Windows.Forms.Clipboard.GetDataObject()
at XXX.Forms.ClipboardHelper.<GetClipboardType>b__5()
at XXX.DataProvider.Executor.Execute[TResult](Logger logger, LogLevel level, Func`1 action, Boolean throwUp, TResult defaultValue, String format, Object[] arguments)
at XXX.DataProvider.Executor.Catch[TResult](Logger logger, LogLevel level, Func`1 action, TResult defaultValue, String format, Object[] arguments)
at XXX.DataProvider.Executor.Catch[TResult](Logger logger, Func`1 action, TResult defaultValue, String format, Object[] arguments)
at XXX.Forms.Ribbon.RibbonFormHelper.IsPasteButtonEnabled()
at XXX.Forms.StartForm.XXX.Forms.IClipboardViewer.EnablePasteButton()
at XXX.Forms.Ribbon.RibbonFormHelper.OrderOverview_FocusChangedEvent(Object sender, EventArgs e)
at DevExpress.XtraVerticalGrid.VGridControlBase.ActivateEditor(RowValueInfo cell)
at DevExpress.XtraVerticalGrid.NormalState.MouseDown(MouseEventArgs e)
at DevExpress.XtraVerticalGrid.BaseHandler.MouseDown(MouseEventArgs e)
at DevExpress.XtraVerticalGrid.VGridControlBase.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)
at DevExpress.XtraVerticalGrid.VGridControlBase.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at XXX.Program.Main(String[] args)
所以,即使我有大量的數據在剪貼板,它應該最終完成。我等了幾分鐘...
現在它再次運作,但我仍然想知道發生了什麼!
* 「當關注對象的變化」 * - 您可以使用[剪貼板事件](http://stackoverflow.com/q/621577/1997232)來代替。在指責剪貼板之前,您可以創建並向我們展示[mcve](https://stackoverflow.com/help/mcve)嗎?最好不使用DevExpress(參見[this](https://www.devexpress.com/Support/Center/Question/Details/T447517))。 – Sinatr
@Sinatr我再也不能自己複製它了。我很幸運地拿到調用堆棧(serveral的時間,有時發生在backgroundworker_completed,有時它發生以後) – toATwork