近来有一个html页面,内容基本如下:
<html>
<head>
<meta http-equiv="Content-Type" contect="text/html" charset="utf-8">
</head>
<form method="POST" action="/hello">
姓名:
<textarea name="name" cols="60" rows="10"></textarea>
<input type=submit name=submit value="OK">
<br>请选择类型:
<input type="radio" name="type" value="1" checked> 类型1
<input type="radio" name="type" value="2" > 类型2
<input type="radio" name="type" value="3" > 类型3
<input type="radio" name="type" value="4" > 类型4
<input type="radio" name="type" value="5" > 类型5
<input type="radio" name="type" value="6" > 类型6
</form>
</html>
为了测试用户点击该页面submit按钮,后台程序的处理结果和反应速度,故研究测试相关内容。
*****以下内容暂时和以上内容无关*****
今天先写C#的多线程相关。
首现引入using System.Threading;
为了记录日志,再引入
using log4net;
using System.Web;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
在程序中,实例化
static ILog log = log4net.LogManager.GetLogger("Log4Net.ProLogThread1");
接下来有两个步骤,定义工作函数和多线程调用工作函数。
我们的工作函数:
static void doWork(object data)
{
Console.WriteLine("Static thread procedure. Data='{0}'", data);
log.Info(data);
}
注意:参数是object形式,对参数的处理操作是在控制台打印和写入日志文件。
多线程调用函数:
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);
}
}
注意:Thread类的构造函数的参数是函数名称,然后在其实例对象调用Start方法,并传入参数。
最后,在主函数Main里面调用testDoWork函数即可运行程序。
问题:
1、在控制台打印了日志的内容,不知为什么?
2、文本的处理顺序不完全是按照原来文本的顺序,不知道线程是否做了优化?
3、囫囵吞枣,还是有很多细节需要细细研究。