public void Run() { while (true) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.UpArrow: UpHandler?.Invoke(); break; case ConsoleKey.DownArrow: DownHandler?.Invoke(); break; case ConsoleKey.LeftArrow: LeftHandler?.Invoke(); break; case ConsoleKey.RightArrow: RightHandler?.Invoke(); break; case ConsoleKey.Escape: return; } } }
public bool ProcessKey(ConsoleKey key) { switch (key) { case ConsoleKey.LeftArrow: LeftHandler?.Invoke(); break; case ConsoleKey.RightArrow: RightHandler?.Invoke(); break; case ConsoleKey.UpArrow: TopHandler?.Invoke(); break; case ConsoleKey.DownArrow: DownHandler?.Invoke(); break; default: return(false); } return(true); }
/// <summary>Used internally. If overridden, call this method first. Only creates the down_handler thread /// if down_thread is true /// </summary> public virtual void startDownHandler() { if (down_thread) { if (down_handler == null) { down_queue = new Alachisoft.NCache.Common.DataStructures.Queue(); down_handler = new DownHandler(down_queue, this); down_handler.Start(); } } }
// Public methods /////////////////////// public static bool MapDown( Mod mods, Key key, bool isRepeating, Action action ) { if (!downHandlers.ContainsKey(mods)) { downHandlers[mods] = new Dictionary <Key, DownHandler>(); } if (downHandlers[mods].ContainsKey(key)) { return(false); } downHandlers[mods][key] = new DownHandler { action = action, isRepeating = isRepeating, }; return(true); }
/// <summary> /// Class for moving by pressing arrow buttons /// </summary> public void Move() { while (true) { var key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.LeftArrow: { LeftHandler?.Invoke(this, EventArgs.Empty); break; } case ConsoleKey.RightArrow: { RightHandler?.Invoke(this, EventArgs.Empty); break; } case ConsoleKey.UpArrow: { UpHandler?.Invoke(this, EventArgs.Empty); break; } case ConsoleKey.DownArrow: { DownHandler?.Invoke(this, EventArgs.Empty); break; } default: { Console.WriteLine("Wrong key was pressed"); break; } } } }
/// <summary>Used internally. If overridden, call this method first. Only creates the down_handler thread /// if down_thread is true /// </summary> public virtual void startDownHandler() { if (down_thread) { if (down_handler == null) { down_queue = new Alachisoft.NCache.Common.DataStructures.Queue(); down_handler = new DownHandler(down_queue, this); if (down_thread_prio >= 0) { try { //down_handler.Priority = System.Threading.ThreadPriority.AboveNormal; } catch (System.Exception t) { stack.NCacheLog.Error("Protocol.startDownHandler()", "priority " + down_thread_prio + " could not be set for thread: " + t.StackTrace); } } down_handler.Start(); } } }
/// <summary>Used internally. If overridden, call parent's method first </summary> public virtual void stopInternal() { if(up_queue != null) up_queue.close(false); // this should terminate up_handler thread if (up_handler != null && up_handler.IsAlive) { try { up_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (up_handler != null && up_handler.IsAlive) { up_handler.Interrupt(); // still alive ? let's just kill it without mercy... try { up_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (up_handler != null && up_handler.IsAlive) stack.NCacheLog.Error("Protocol", "up_handler thread for " + Name + " was interrupted (in order to be terminated), but is still alive"); } } up_handler = null; if(down_queue != null) down_queue.close(false); // this should terminate down_handler thread if (down_handler != null && down_handler.IsAlive) { try { down_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (down_handler != null && down_handler.IsAlive) { down_handler.Interrupt(); // still alive ? let's just kill it without mercy... try { down_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (down_handler != null && down_handler.IsAlive) stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } down_handler = null; }
/// <summary>Used internally. If overridden, call parent's method first </summary> public virtual void stopInternal() { if (up_queue != null) { up_queue.close(false); // this should terminate up_handler thread } if (up_handler != null && up_handler.IsAlive) { try { up_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (up_handler != null && up_handler.IsAlive) { up_handler.Interrupt(); // still alive ? let's just kill it without mercy... try { up_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (up_handler != null && up_handler.IsAlive) { stack.NCacheLog.Error("Protocol", "up_handler thread for " + Name + " was interrupted (in order to be terminated), but is still alive"); } } } up_handler = null; if (down_queue != null) { down_queue.close(false); // this should terminate down_handler thread } if (down_handler != null && down_handler.IsAlive) { try { down_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (down_handler != null && down_handler.IsAlive) { down_handler.Interrupt(); // still alive ? let's just kill it without mercy... try { down_handler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (down_handler != null && down_handler.IsAlive) { stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } } down_handler = null; }
public override void stopInternal() { //stop up handlers if (_sequencelessMsgUpQueue != null) _sequencelessMsgUpQueue.close(false); // this should terminate up_handler thread if (_sequencelessMsgUpHandler != null && _sequencelessMsgUpHandler.IsAlive) { try { _sequencelessMsgUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (_sequencelessMsgUpHandler != null && _sequencelessMsgUpHandler.IsAlive) { _sequencelessMsgUpHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _sequencelessMsgUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message); } if (_sequencelessMsgUpHandler != null && _sequencelessMsgUpHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "up_handler thread for " + Name + " was interrupted (in order to be terminated), but is still alive"); } } _sequencelessMsgUpHandler = null; if (_sequenecedMsgUpQueue != null) _sequenecedMsgUpQueue.close(false); // this should terminate down_handler thread if (_sequencedMsgUpHandler != null && _sequencedMsgUpHandler.IsAlive) { try { _sequencedMsgUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_sequencedMsgUpHandler != null && _sequencedMsgUpHandler.IsAlive) { _sequencedMsgUpHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _sequencedMsgUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_sequencedMsgUpHandler != null && _sequencedMsgUpHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } _sequencedMsgUpHandler = null; if (_tokenMsgUpQueue != null) _tokenMsgUpQueue.close(false); // this should terminate down_handler thread if (_tokenSeekingUpHandler != null && _tokenSeekingUpHandler.IsAlive) { try { _tokenSeekingUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_tokenSeekingUpHandler != null && _tokenSeekingUpHandler.IsAlive) { _tokenSeekingUpHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _tokenSeekingUpHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_tokenSeekingUpHandler != null && _tokenSeekingUpHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } _tokenSeekingUpHandler = null; ///stop down handler now. if (_unicastDownQueue != null) _unicastDownQueue.close(false); // this should terminate down_handler thread if (_unicastDownHandler != null && _unicastDownHandler.IsAlive) { try { _unicastDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_unicastDownHandler != null && _unicastDownHandler.IsAlive) { _unicastDownHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _unicastDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_unicastDownHandler != null && _unicastDownHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } _unicastDownHandler = null; if (_multicastDownQueue != null) _multicastDownQueue.close(false); // this should terminate down_handler thread if (_multicastDownHandler != null && _multicastDownHandler.IsAlive) { try { _multicastDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_multicastDownHandler != null && _multicastDownHandler.IsAlive) { _multicastDownHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _multicastDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_multicastDownHandler != null && _multicastDownHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } _multicastDownHandler = null; if (_tokenSeekingMsgDownQueue != null) _tokenSeekingMsgDownQueue.close(false); // this should terminate down_handler thread if (_tokenSeekingMsgDownHandler != null && _tokenSeekingMsgDownHandler.IsAlive) { try { _tokenSeekingMsgDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_tokenSeekingMsgDownHandler != null && _tokenSeekingMsgDownHandler.IsAlive) { _tokenSeekingMsgDownHandler.Interrupt(); // still alive ? let's just kill it without mercy... try { _tokenSeekingMsgDownHandler.Join(THREAD_JOIN_TIMEOUT); } catch (System.Exception e) { Stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message); } if (_tokenSeekingMsgDownHandler != null && _tokenSeekingMsgDownHandler.IsAlive) Stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive"); } } _tokenSeekingMsgDownHandler = null; }
public override void startDownHandler() { if (down_thread) { if (_unicastDownHandler == null) { _unicastDownQueue = new Alachisoft.NCache.Common.DataStructures.Queue(); _unicastDownHandler = new DownHandler(_unicastDownQueue, this, Name + ".unicast.DownHandler", 1); if (down_thread_prio >= 0) { try { } catch (System.Exception t) { Stack.NCacheLog.Error("Protocol.startDownHandler()", "priority " + down_thread_prio + " could not be set for thread: " + t.StackTrace); } } _unicastDownHandler.Start(); } if (_multicastDownHandler == null) { _multicastDownQueue = new Alachisoft.NCache.Common.DataStructures.Queue(); _multicastDownHandler = new DownHandler(_multicastDownQueue, this, Name + ".muticast.DownHandler", 2); if (down_thread_prio >= 0) { try { } catch (System.Exception t) { Stack.NCacheLog.Error("Protocol.startDownHandler()", "priority " + down_thread_prio + " could not be set for thread: " + t.StackTrace); } } _multicastDownHandler.Start(); } if (_tokenSeekingMsgDownHandler == null) { _tokenSeekingMsgDownQueue = new Alachisoft.NCache.Common.DataStructures.Queue(); _tokenSeekingMsgDownHandler = new DownHandler(_tokenSeekingMsgDownQueue, this, Name + ".token.DownHandler", 3); if (down_thread_prio >= 0) { try { } catch (System.Exception t) { Stack.NCacheLog.Error("Protocol.startDownHandler()", "priority " + down_thread_prio + " could not be set for thread: " + t.StackTrace); } } _tokenSeekingMsgDownHandler.Start(); } } }
public BlockingDownstreamHandler(DownHandler handler) { _handler = handler; }