public ColorMessage DispatchPromptEvent(ColorMessage colorPrompt) { if (PromptEvent == null) { return(colorPrompt); } foreach (PromptEventDelegate del in PromptEvent.GetInvocationList()) { try { colorPrompt = del(colorPrompt); } catch (Exception e) { ChiConsole.WriteError("Error calling prompt handler", e); } if (colorPrompt == null) { break; } } return(colorPrompt); }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole() { while (true) { #if !NET_4_0 if (!Processing) { throw new Exception("Restart"); } lock (m_consoleLock) { if (action == null) { action = Prompt; result = action.BeginInvoke(null, null); m_calledEndInvoke = false; } try { if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne(5000, false) || !result.IsCompleted)) { } else if (action != null && !result.CompletedSynchronously && !m_calledEndInvoke) { m_calledEndInvoke = true; action.EndInvoke(result); action = null; result = null; } } catch (Exception ex) { //Eat the exception and go on Output("[Console]: Failed to execute command: " + ex.ToString()); action = null; result = null; } } #else Task prompt = TaskEx.Run(() => { Prompt(); }); if (!Processing) { throw new Exception("Restart"); } while (!Task.WaitAll(new Task[1] { prompt }, 1000)) { if (!Processing) { throw new Exception("Restart"); } } #endif } }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole() { WaitHandle[] wHandles = new WaitHandle[1]; if (result != null) { wHandles[0] = result.AsyncWaitHandle; } Timer t = new Timer { Interval = 0.5 }; t.Elapsed += t_Elapsed; t.Start(); while (true) { if (!Processing) { throw new Exception("Restart"); } lock (m_consoleLock) { if (action == null) { action = Prompt; result = action.BeginInvoke(null, null); m_calledEndInvoke = false; } try { if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne(5000, false) || !result.IsCompleted)) { } else if (action != null && !result.CompletedSynchronously && !m_calledEndInvoke) { m_calledEndInvoke = true; action.EndInvoke(result); action = null; result = null; } } catch (Exception ex) { //Eat the exception and go on Output("[Console]: Failed to execute command: " + ex); action = null; result = null; } } } }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole() { WaitHandle[] wHandles = new WaitHandle[1]; if (result != null) { wHandles[0] = result.AsyncWaitHandle; } System.Timers.Timer t = new System.Timers.Timer (); t.Interval = 0.5; t.Elapsed += new System.Timers.ElapsedEventHandler (t_Elapsed); t.Start (); while (true) { if (!Processing) { throw new Exception ("Restart"); } lock (m_consoleLock) { if (action == null) { action = Prompt; result = action.BeginInvoke (null, null); m_calledEndInvoke = false; } try { if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne (5000, false) || !result.IsCompleted)) { } else if (action != null && !result.CompletedSynchronously && !m_calledEndInvoke) { m_calledEndInvoke = true; action.EndInvoke (result); action = null; result = null; } } catch (Exception ex) { //Eat the exception and go on Output ("[Console]: Failed to execute command: " + ex.ToString ()); action = null; result = null; } } } }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole () { while (true) { #if !NET_4_0 if (!Processing) { throw new Exception ("Restart"); } lock (m_consoleLock) { if (action == null) { action = Prompt; result = action.BeginInvoke (null, null); m_calledEndInvoke = false; } try { if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne (5000, false) || !result.IsCompleted)) { } else if (action != null && !result.CompletedSynchronously && !m_calledEndInvoke) { m_calledEndInvoke = true; action.EndInvoke (result); action = null; result = null; } } catch(Exception ex) { //Eat the exception and go on Output ("[Console]: Failed to execute command: " + ex.ToString ()); action = null; result = null; } } #else Task prompt = TaskEx.Run(() => { Prompt(); }); if (!Processing) throw new Exception("Restart"); while (!Task.WaitAll(new Task[1] { prompt }, 1000)) { if (!Processing) throw new Exception("Restart"); } #endif } }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole() { while (true) { if (!Processing) { throw new Exception("Restart"); } try { if (action == null) { action = Prompt; result = action.BeginInvoke(null, null); } if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne(1000, false) || !result.IsCompleted)) { } else { action.EndInvoke(result); action = null; result = null; } } catch (Exception e) { m_log.ErrorFormat("Command error: {0}", e); } } }
/// <summary> /// Starts the prompt for the console. This will never stop until the region is closed. /// </summary> public void ReadConsole() { while (true) { if (!Processing) { throw new Exception("Restart"); } try { lock (m_consoleLock) { if (action == null) { action = Prompt; result = action.BeginInvoke(null, null); m_calledEndInvoke = false; } try { if ((!result.IsCompleted) && (!result.AsyncWaitHandle.WaitOne(1000, false) || !result.IsCompleted)) { } else if (action != null && !result.CompletedSynchronously && !m_calledEndInvoke) { m_calledEndInvoke = true; action.EndInvoke(result); action = null; result = null; } } catch { //Eat the exception and go on action = null; result = null; } } } catch (Exception e) { m_log.ErrorFormat("Command error: {0}", e); } } }