HI everyone...
when I close my application, it always stays with the active processes, each time I remove it from task manager, what do I do?
this is class listen
class Listener
{
public delegate void lbconnection(string lbconnection);
public lbconnection lbc;
Thread thdsHandler;
public int lport;
public string lpath;
public Listener(int port,string path,lbconnection lbcc)
{
lbc=lbcc;
lport = port;
lpath = path;
}
public TcpClient handlerSocket;
public TcpListener tcpListener;
public void listenerThread()
{
tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, lport));
tcpListener.Start();
while (true)
{
handlerSocket = tcpListener.AcceptTcpClient();
if (handlerSocket.Connected)
{
lbc("Connected To Localhost :" + lport + " connected.");
lock (this)
{
Request rqs = new Request(lpath, handlerSocket);
thdsHandler = new Thread(new ThreadStart(rqs.handlerThread));
thdsHandler.Start();
}
}
}
}
public void killthread()
{
thdsHandler.Abort();
}
}
and the request class
class Request
{
public string tbpath;
public TcpClient tcpclient;
public Request(string tbpath, TcpClient tcpclient)
{
this.tbpath = tbpath;
this.tcpclient = tcpclient;
}
public struct serverinfo
{
public string httpversion;
public string Date;
public string sinfo;
public string AcceptRanges;
public string ContentLength;
public string Connection;
public string ContentType;
};
public void handlerThread()
{
byte[] clientData = new byte[1024];
String filename = "";
String[] verbs;
NetworkStream ns = tcpclient.GetStream();
ns.Read(clientData, 0, clientData.Length);
string stringdata = Encoding.ASCII.GetString(clientData);
File.WriteAllText(tbpath + "\\Request.txt", stringdata);
verbs = stringdata.Split(" ".ToCharArray());
filename = verbs[1].Replace("/", "\\");
if (filename.IndexOf("?") != -1)
{
filename = filename.Substring(0, filename.IndexOf("?"));
}
if (filename.EndsWith("\\"))
{
filename += "index.html";
}
filename = tbpath + filename;
if (!File.Exists(filename))
{
filename = tbpath + "\\Page Not Found.html";
}
FileStream fs = new FileStream(filename, FileMode.Open);
fs.Seek(0, SeekOrigin.Begin);
byte[] fileContents = new byte[fs.Length];
fs.Read(fileContents, 0, (int)fs.Length);
fs.Close();
ns.Write(fileContents, 0, fileContents.Length);
serverinfo sinfo = new serverinfo();
sinfo.httpversion = "HTTP/1.1 200 OK \r\n";
sinfo.Date = "Dtae: ";
sinfo.sinfo = "Server: HTTPServer/1 (Windows) HTTP/1.1 \r\n";
sinfo.AcceptRanges = "Accept-Ranges: bytes \r\n";
sinfo.ContentLength = "Content-Length: 1564 \r\n";
sinfo.Connection = "Connection: Close \r\n";
sinfo.ContentType = "Content-Type: text/html \r\n";
string servinfo = sinfo.httpversion + sinfo.Date + DateTime.Now.Date + "," + DateTime.Now.Month + " " + DateTime.Now.Year + " " + DateTime.Now.Hour + " " + DateTime.Now.Minute + " "
+ DateTime.Now.Second + "\r\n" + sinfo.sinfo + sinfo.AcceptRanges + sinfo.ContentLength + sinfo.Connection + sinfo.ContentType + "\r\n" + Encoding.ASCII.GetString(fileContents);
File.WriteAllText("C:\\www\\Reponse.txt", servinfo);
ns.Close();
}
}
and the click bouton
private void btnStart_Click(object sender, EventArgs e)
{
tbPort.ReadOnly = true;
tbPath.ReadOnly = true;
int port = 0;
port = Convert.ToInt16(tbPort.Text);
string path = tbPath.Text;
Listener lst = new Listener(port, path, this.lbconnect);
thdListener = new Thread(new ThreadStart(lst.listenerThread));
thdListener.Start();
btnStart.Enabled = false;
Resume.Enabled = false;
Suspend.Enabled = true;
Stop.Enabled = true;
}
this is my work and i need to explain me the wrong ...