Sign in to follow this  

How to restart a Thread in C# .Net 4.0?

This topic is 2141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using C# .Net4.0 in VS 2010.
How do I restart a Thread?
Its like I want to Abort() the thread and Start() it from the beginning again?
Is it possible?

Share this post


Link to post
Share on other sites
No, this isn't possible, as far as I know. But what are you actually trying to do? There will be an alternative.

Share this post


Link to post
Share on other sites
I have a thread which is started when the user clicks the 'Start' button.
Actually this is implementing a server which initializes a socket and then loops the [i]socket.Accept()[/i].
I want to allow the user to stop the server, thus closing the thread; and then restarting it any number of times.

Share this post


Link to post
Share on other sites
Firstly, calling abort on a thread is generally a bad idea. If you want to do this correctly then you should be using beginaccept/endaccept. If you don't want to use the IOCP functionality in the .net framework then you should at least use select and only when something is available call accept. Then you can have the select in a short timeout and periodically check a boolean condition that will notify you when the thread should terminate.

Share this post


Link to post
Share on other sites

This topic is 2141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this