المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Form Not Closing



C# Programming
01-29-2010, 08:52 AM
I have this function that is called from the constructor of the main form:

private void InitNet()
{
listener= new TcpListener(localAddress, portNo);
listenForConnection = new Thread(StartListening);
listenForConnection.Start();
Control.CheckForIllegalCrossThreadCalls = false;
}

The StartListening function is defined as follows:

private void StartListening()
{
listener.Start();
while (true)
{
Networks user = new Networks(listener.AcceptTcpClient());
}
}

When i close the program, it does not get out of memory, possible because of the thread. I have tried to abort the thread in the FormClosing Event but this did not work, how can i close this application competely (Of course not using task manager! http://www.barakasoft.com/script/Forums/Images/smiley_tongue.gif )

Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.