Esempio n. 1
0
        /// <summary>
        ///     Start watching mouse events
        /// </summary>
        public void Start()
        {
            lock (accesslock)
            {
                if (!isRunning)
                {
                    taskCancellationTokenSource = new CancellationTokenSource();
                    mouseQueue = 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(() =>
                    {
                        mouseHook              = new MouseHook();
                        mouseHook.MouseAction += MListener;
                        mouseHook.Start();
                    },
                                          CancellationToken.None,
                                          TaskCreationOptions.None,
                                          factory.GetTaskScheduler()).Wait();

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

                    isRunning = true;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Start watching
        /// </summary>
        public void Start()
        {
            // 和Stop() 互斥
            lock (accesslock)
            {
                if (!isRunning)
                {
                    // 创建异步队列
                    taskCancellationTokenSource = new CancellationTokenSource();
                    keyQueue = new AsyncConcurrentQueue <object>(taskCancellationTokenSource.Token);

                    //This needs to run on UI thread context
                    //So use task factory with the shared UI message pump thread
                    // 在UI线程中启动Hook,生产者作为Hook的回调函数。
                    Task.Factory.StartNew(() =>
                    {
                        keyboardHook          = new KeyboardHook();
                        keyboardHook.KeyDown += KListener;
                        keyboardHook.KeyUp   += KListener;
                        keyboardHook.Start();
                    },
                                          CancellationToken.None,
                                          TaskCreationOptions.None,
                                          factory.GetTaskScheduler()).Wait();

                    // 启动消费者
                    Task.Factory.StartNew(() => ConsumeKeyAsync());

                    // 记录watcher状态
                    isRunning = true;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 ///     Start watching print events
 /// </summary>
 public void Start()
 {
     lock (accesslock)
     {
         if (!isRunning)
         {
             Task.Factory.StartNew(() =>
             {
                 isRunning   = true;
                 printers    = new ArrayList();
                 printServer = new PrintServer();
                 foreach (var pq in printServer.GetPrintQueues())
                 {
                     var pqm = new PrintQueueHook(pq.Name);
                     pqm.OnJobStatusChange += pqm_OnJobStatusChange;
                     pqm.Start();
                     printers.Add(pqm);
                 }
             },
                                   CancellationToken.None,
                                   TaskCreationOptions.None,
                                   factory.GetTaskScheduler()).Wait();
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Start to watch
        /// </summary>
        public void Start()
        {
            lock (accesslock)
            {
                if (!isRunning)
                {
                    activeWindows = new Dictionary <IntPtr, WindowData>();
                    prevTimeApp   = DateTime.Now;

                    taskCancellationTokenSource = new CancellationTokenSource();
                    appQueue = 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(() =>
                    {
                        windowHook = new WindowHook(factory);
                        windowHook.WindowCreated   += WindowCreated;
                        windowHook.WindowDestroyed += WindowDestroyed;
                        windowHook.WindowActivated += WindowActivated;
                    },
                                          CancellationToken.None,
                                          TaskCreationOptions.None,
                                          factory.GetTaskScheduler()).Wait();

                    lastEventWasLaunched = false;
                    lastHwndLaunched     = IntPtr.Zero;

                    Task.Factory.StartNew(() => AppConsumer());
                    isRunning = true;
                }
            }
        }
        /// <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;
                }
            }
        }