Public partial class loghelper {Private Static queue <string> queue; public static void writelog (string MSG) {// lock the Write File, prevent multiple threads from writing files at the same time and report exceptions // locking problem: causing user waiting // lock ("A") // {// file. appendalltext (@ "C: \ Users \ Q1 \ Desktop \ a.txt", MSG); // wait: Write to memory instead of hard disk, write and read queue first. enqueue (MSG);} static loghelper () {queue = new queue <string> (); writedisk () ;}// define a method, write the error message in the memory to the Private Static void writedisk () {thread t = new thread () => {While (true) {If (queue. count> 0) {string MSG = queue. dequeue (); file. appendalltext (@ "C: \ Users \ Q1 \ Desktop \ a.txt", MSG + "\ r \ n ----------------------------------- \ r \ n");} else {thread. sleep (5000) ;}}); T. isbackground = true; T. start ();}}
17 ------ error message writing log class