Closed wy-luke closed 1 year ago
I assume that this could happen if you call StartMonitoring() after calling StopMonitoring(). So this cannot be restarted once stopped as the internal code does not recreate the ClipboardHandle.
For sure we can fix this by making StartMonitoring() ensure the ClipboardHandle creation. Or we can just re instantiate a new SharpClipboard instance.
I wouldn't worry about this too much, And I guess it has nothing to do with cutting text. Copying text or anything need to access the handle could also trigger this issue.
I assume that this could happen if you call StartMonitoring() after calling StopMonitoring(). So this cannot be restarted once stopped as the internal code does not recreate the ClipboardHandle.
For sure we can fix this by making StartMonitoring() ensure the ClipboardHandle creation. Or we can just re instantiate a new SharpClipboard instance.
I wouldn't worry about this too much, And I guess it has nothing to do with cutting text. Copying text or anything need to access the handle could also trigger this issue.
yeah, you're right. In my app, I need to monitor the clipboard, once it changed, I make some changes to the text and make the new text to the clipboard. If I don't stop monitor before set the new text, it will be in endless loop.
But I recreate a new instance before I start monitoring again, I don't know if that helps.
Now I have switch to another method to monitor the clipboard and the annoying error dialog don't show up any more.🤣But the problem is not be solved completely. Because I dont konw why even I -= the ClipboardChanged event
before set the modified text to clipboard, it still invoke the event once more. And sometimes it will invoke just once.😭😭😭
Can you please help me? thanks so much!
System.ObjectDisposedException: '无法访问已释放的对象。 ObjectDisposed_ObjectName_Name'
This exception was originally thrown at this call stack: [External Code]
System.ObjectDisposedException HResult=0x80131622 Message=无法访问已释放的对象。 ObjectDisposed_ObjectName_Name Source=System.Windows.Forms StackTrace: at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Form.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Control.SetVisibleCore(Boolean value) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.Show() at WK.Libraries.SharpClipboardNS.SharpClipboard.StartMonitoring() at WK.Libraries.SharpClipboardNS.SharpClipboard.OnLoad(Object sender, EventArgs e) at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at CopyPlusPlus.App.Main()
This exception was originally thrown at this call stack: [External Code]