private static void ListenerOutputProc(object state) { TextBoxTraceListener listener = (TextBoxTraceListener)state; while (true) { int waitRet = WaitHandle.WaitAny(new WaitHandle[] { listener.mOutputReadySemaphore, listener.mCancelEvent }); if (waitRet != 0) { break; } ArrayList traceLines = listener.mTraceLines; String sLines = String.Empty; DateTime dtNow = DateTime.Now; while (true) { sLines += String.Format("[{0:00}:{1:00}:{2:00}:{3:000}] {4}", dtNow.Hour, dtNow.Minute, dtNow.Second, dtNow.Millisecond, traceLines[0] as string); traceLines.RemoveAt(0); if (!listener.mOutputReadySemaphore.WaitOne(0)) { break; } } try { listener.mTextBox.Invoke(listener.writeInvokeCb, new object[] { sLines }); } catch { break; } } }
private void fHandleTest_Load(object sender, EventArgs e) { mListener = new TextBoxTraceListener(txtOutput, ThreadPriority.Lowest); Debug.Listeners.Add(mListener); }