1. Trace & Debug
Understand the difference between the two, Trace has a listners.add () very useful, there is an online in the ListBox output Debug and trace information
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Diagnostics;9 usingSystem.Windows.Forms;Ten usingSystem.Threading; One A namespacecontroltest - { - Public Partial classForm1:form the { - PublicForm1 () - { - InitializeComponent (); +TRACE.LISTENERS.ADD (NewListboxlogtracelistener (ListBox1)); -DEBUG.LISTENERS.ADD (NewTextWriterTraceListener (System.IO.File.CreateText ("Log.txt"))); +Debug.autoflush =true; A } at - Private voidForm1_Load (Objectsender, EventArgs e) - { - //thread newthread = new Thread (new ThreadStart (run)); - //Newthread.start (); - } in - Private voidButton1_Click (Objectsender, EventArgs e) to { +Debug.WriteLine (string. Format ("{0}: {1}", DateTime.Now,"Debug msg ...")); - } the * Private voidButton2_Click (Objectsender, EventArgs e) $ {Panax NotoginsengTrace.WriteLine (string. Format ("{0}: {1}", DateTime.Now,"Trace msg ...")); - } the Private voidRun () + { A while(true) the { +Debug.WriteLine ("Debug msg ..."); -Thread.Sleep ( +); $Trace.WriteLine ("Trace msg ..."); $Thread.Sleep ( +); - } - } the } - Wuyi Public classListboxlogtracelistener:defaulttracelistener the { - PrivateListBox M_listbox {Get;Set; } Wu PublicListboxlogtracelistener (ListBox listbox) - { AboutM_listbox =ListBox; $ } - Public Override voidWriteLine (stringmessage) - { - if(!m_listbox.visible)return; A if(m_listbox.invokerequired) + { theM_listbox.begininvoke (NewMethodInvoker (Delegate{WriteLine (message);})); - return; $ } the M_LISTBOX.ITEMS.ADD (message); the } the } the}View Code
. net:c#: System.Diagnostics