Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
How to stop thread??
aggil antony
16y
16k
1
Reply
I'm doing a Network project . I used a function to listen to clients and maked it as a thread. The main problem is when I closed the application,the main window closes and the application runs in background.I cannot close the application Even from the Task Manager.
Code used
private void MainForm_Load(object sender, EventArgs e)
{
th = new Thread(new ThreadStart(listen));
th.Start();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
shut=1;
th.Abort();
}
public void listen()
{
ss.Bind(new IPEndPoint(IPAddress.Any, 4000));
ss.Listen(-1);
while (shut==0)
{
cs = ss.Accept();
c1 = 0;
mysocket[i] = cs;
i++;
clientsock = cs;
ThreadPool.QueueUserWorkItem(new WaitCallback(listensend), clientsock);
}
}
Also the socket string used is
Socket ss = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Can I close the Application forcibly?
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
Print Selected Pages Using PrintDialog
creating instances of classes in separate files