Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Shashwat Rohilla   Members   -  Reputation: 130

Like
0Likes
Like

Posted 06 March 2012 - 04:37 AM

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?

Sponsor:

#2 TheUnbeliever   Members   -  Reputation: 961

Like
0Likes
Like

Posted 06 March 2012 - 08:12 AM

No, this isn't possible, as far as I know. But what are you actually trying to do? There will be an alternative.
[TheUnbeliever]

#3 Shashwat Rohilla   Members   -  Reputation: 130

Like
0Likes
Like

Posted 06 March 2012 - 10:42 PM

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 socket.Accept().
I want to allow the user to stop the server, thus closing the thread; and then restarting it any number of times.

#4 Washu   Senior Moderators   -  Reputation: 4555

Like
0Likes
Like

Posted 06 March 2012 - 11:32 PM

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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS