我的示例需要一些帮助。我需要创建一个http服务器,它将同时处理多个请求。 到现在为止,我正在为此任务使用其他线程。
private void button1_Click(object sender, EventArgs e)
{
try
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://192.168.0.214:8282/");
listener.Start();
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
while (true)
{
HttpListenerContext context = listener.GetContext();
string methodName = Convert.ToString(context.Request.Url);
string Response = "Response";
HttpListenerResponse response = context.Response;
string responseString = Convert.ToString(Response);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
}).Start();
}
catch
{
}
}
我的问题是,这个示例可以同时处理多个请求吗?