Recently, there is an HTML page with the following content:
<HTML>
In order to test the processing result and response speed of the background program by clicking the submit button on this page, the test content is studied.
* ***** The following content is temporarily irrelevant to the above content *****
Write the multi-threading related to C # first today.
Using system. Threading;
To record the log, introduce
Using log4net;
Using system. Web;
[Assembly: log4net. config. xmlconfigurator (watch = true)]
In the program, instantiate
Static ilog log = log4net. logmanager. getlogger ("log4net. prologthread1 ");
There are two steps to define a work function and call a work function in multiple threads.
Our work functions:
static void doWork(object data) { Console.WriteLine("Static thread procedure. Data='{0}'", data); log.Info(data); }
Note: parameters are in the form of objects. The processing operations on parameters are to print and write log files on the console.
Multi-threaded function call:
static void testDoWork() { try { using (StreamReader sr = new StreamReader("E:\\ThreadTest\\text.txt")) { String line; while ((line = sr.ReadLine()) != null) { Thread newThread = new Thread(doWork); newThread.Start(line); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
Note: The parameter of the constructor of the thread class is the function name, and then the start method is called on its instance object, and the parameter is input.
Finally, call the testdowork function in the main function to run the program.
Problem:
1. I printed the log Content on the console. Why?
2. The text processing order is not completely in the original text order. Do you know whether the thread has been optimized?
3. There are still many details that need to be carefully studied.