/// <summary> /// Start to watch /// </summary> public static void Start() { if (!isRunning) { lock (accesslock) { activeWindows = new List <WindowData> { }; prevTimeApp = DateTime.Now; appQueue = new AsyncCollection <object>(); //This needs to run on UI thread context //So use task factory with the shared UI message pump thread Task.Factory.StartNew(() => { }).ContinueWith(x => { WindowHook.WindowCreated += new GeneralShellHookEventHandler(WindowCreated); WindowHook.WindowDestroyed += new GeneralShellHookEventHandler(WindowDestroyed); WindowHook.WindowActivated += new GeneralShellHookEventHandler(WindowActivated); }, SharedMessagePump.GetTaskScheduler()); lastEventWasLaunched = false; lastHwndLaunched = IntPtr.Zero; Task.Factory.StartNew(() => AppConsumer()); isRunning = true; } } }
/// <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(); } } } } }
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(); } } } } }
public static void Start() { if (!_IsRunning) { lock (_Accesslock) { _activeWindows = new List <WindowData> { }; _prevTimeApp = DateTime.Now; appQueue = new AsyncCollection <object>(); Task.Factory.StartNew(() => { }).ContinueWith(x => { WindowHook.WindowCreated += new GeneralShellHookEventHandler(WindowCreated); WindowHook.WindowDestroyed += new GeneralShellHookEventHandler(WindowDestroyed); WindowHook.WindowActivated += new GeneralShellHookEventHandler(WindowActivated); }, SharedMessagePump.GetTaskScheduler()); _lastEventWasLaunched = false; _lastHwndLaunched = IntPtr.Zero; Task.Factory.StartNew(() => AppConsumer()); _IsRunning = true; } } }
static WindowHook() { if (sh == null) { sh = new ShellHook(SharedMessagePump.GetHandle()); sh.WindowCreated += new GeneralShellHookEventHandler(WindowCreatedEvent); sh.WindowDestroyed += new GeneralShellHookEventHandler(WindowDestroyedEvent); sh.WindowActivated += new GeneralShellHookEventHandler(WindowActivatedEvent); } }
/// <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); } } }
public static void Start() { if (!_IsRunning) { lock (_Accesslock) { _kQueue = new AsyncCollection <object>(); _mh = new MouseHook(); _mh.MouseAction += MListener; Task.Factory.StartNew(() => { }).ContinueWith(x => { _mh.Start(); }, SharedMessagePump.GetTaskScheduler()); Task.Factory.StartNew(() => ConsumeKeyAsync()); _IsRunning = true; } } }
/// <summary> /// Start watching mouse events /// </summary> public static void Start() { if (!isRunning) { lock (accesslock) { mouseQueue = new AsyncCollection <object>(); mouseHook = new MouseHook(); mouseHook.MouseAction += MListener; //low level hooks need to be registered in the context of a UI thread Task.Factory.StartNew(() => { }).ContinueWith(x => { mouseHook.Start(); }, SharedMessagePump.GetTaskScheduler()); Task.Factory.StartNew(() => ConsumeKeyAsync()); isRunning = true; } } }
public static void Start() { if (!_IsRunning) { lock (_Accesslock) { _kQueue = new AsyncCollection <object>(); _kh = new KeyboardHook(); _kh.KeyDown += new RawKeyEventHandler(KListener); _kh.KeyUp += new RawKeyEventHandler(KListener); Task.Factory.StartNew(() => { }).ContinueWith(x => { _kh.Start(); }, SharedMessagePump.GetTaskScheduler()); Task.Factory.StartNew(() => ConsumeKeyAsync()); _IsRunning = true; } } }
/// <summary> /// Start watching /// </summary> public static void Start() { if (!isRunning) { lock (accesslock) { keyQueue = new AsyncCollection <object>(); keyboardHook = new KeyboardHook(); keyboardHook.KeyDown += new RawKeyEventHandler(KListener); keyboardHook.KeyUp += new RawKeyEventHandler(KListener); //low level hooks need to run on the context of a UI thread to hook successfully Task.Factory.StartNew(() => { }).ContinueWith(x => { keyboardHook.Start(); }, SharedMessagePump.GetTaskScheduler()); Task.Factory.StartNew(() => ConsumeKeyAsync()); isRunning = true; } } }