public static void Start()
        {
            if (!_IsRunning)
            {
                lock (_Accesslock)
                {
                    try
                    {
                        _clipQueue = new AsyncCollection <object>();


                        Task.Factory.StartNew(() => { }).ContinueWith(x =>
                        {
                            _clip = new ClipBoardHook();
                            _clip.RegisterClipboardViewer();
                            _clip.ClipBoardChanged += ClipboardHandler;
                        }, SharedMessagePump.GetTaskScheduler());

                        Task.Factory.StartNew(() => ClipConsumerAsync());

                        _IsRunning = true;
                    }
                    catch
                    {
                        if (_clip != null)
                        {
                            Stop();
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Start watching
        /// </summary>
        public static void Start()
        {
            if (!isRunning)
            {
                lock (accesslock)
                {
                    try
                    {
                        clipQueue = new AsyncCollection <object>();

                        //Low level hooks need to be run in the context of a UI thread
                        Task.Factory.StartNew(() => { }).ContinueWith(x =>
                        {
                            clip = new ClipBoardHook();
                            clip.RegisterClipboardViewer();
                            clip.ClipBoardChanged += ClipboardHandler;
                        }, SharedMessagePump.GetTaskScheduler());

                        Task.Factory.StartNew(() => ClipConsumerAsync());

                        isRunning = true;
                    }
                    catch
                    {
                        if (clip != null)
                        {
                            Stop();
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Start watching
        /// </summary>
        public void Start()
        {
            lock (accesslock)
            {
                if (!isRunning)
                {
                    taskCancellationTokenSource = new CancellationTokenSource();
                    clipQueue = new AsyncConcurrentQueue <object>(taskCancellationTokenSource.Token);

                    //This needs to run on UI thread context
                    //So use task factory with the shared UI message pump thread
                    Task.Factory.StartNew(() =>
                    {
                        clip = new ClipBoardHook();
                        clip.RegisterClipboardViewer();
                        clip.ClipBoardChanged += ClipboardHandler;
                    },
                                          CancellationToken.None,
                                          TaskCreationOptions.None,
                                          factory.GetTaskScheduler()).Wait();

                    Task.Factory.StartNew(() => ClipConsumerAsync());

                    isRunning = true;
                }
            }
        }