/// <summary> /// Stop watching /// </summary> public void Stop() { lock (accesslock) { if (isRunning) { if (clip != null) { //This needs to run on UI thread context //So use task factory with the shared UI message pump thread Task.Factory.StartNew(() => { clip.ClipBoardChanged -= ClipboardHandler; clip.UnregisterClipboardViewer(); clip.Dispose(); }, CancellationToken.None, TaskCreationOptions.None, factory.GetTaskScheduler()); } isRunning = false; clipQueue.Enqueue(false); taskCancellationTokenSource.Cancel(); } } }
/// <summary> /// Stop watching /// </summary> public static void Stop() { if (isRunning) { lock (accesslock) { if (clip != null) { Task.Factory.StartNew(() => { }).ContinueWith(x => { clip.ClipBoardChanged -= ClipboardHandler; clip.UnregisterClipboardViewer(); clip.Dispose(); }, SharedMessagePump.GetTaskScheduler()); } isRunning = false; clipQueue.Add(false); } } }