|
-
May 1st, 2007, 09:40 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Pausing a thread
I did a search on this site and all results said to use Thread.Suspend. Now in vs2005 Thread.Suspend is deprecated/obsolete. I checked MSDN and it said that the method will be removed from the next version. Is there a different way to pause a thread?
I have tried to use sleep in a sub like this:
Code:
Sub SuspendThread(ByVal t As Threading.Thread)
While bPaused
t.Sleep(100)
End While
End Sub
But, t.Sleep is underlined green. When I check the tooltip it says, Access of a shared member ... qualifying expression will not be evaluated.
I shortened the message. It wants me to convert t.Sleep to Thread.Sleep. This seems like it may cause the wrong thread to sleep on accident.
Any ideas?
Prefix has no suffix, but suffix has a prefix.
-
May 1st, 2007, 10:41 PM
#2
Re: [2005] Pausing a thread
The Thread.Sleep method ALWAYS sleeps the current thread. There is no way to sleep a thread other than the current thread. If that's the end result you need then you must set a variable that will be read by the target thread that will then sleep itself.
The reason that the Suspend method is being removed is because it makes it too easy to cause deadlock. By calling Sleep repeatedly you avoid that possibility. If you explain why you fell you need to suspend a thread we may be able to suggest a better solution.
-
May 1st, 2007, 10:44 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] Pausing a thread
I just need to pause and resume a thread programmatically. I will try to use the sleep method.
Prefix has no suffix, but suffix has a prefix.
-
May 1st, 2007, 10:51 PM
#4
Re: [2005] Pausing a thread
 Originally Posted by Troy Lundin
I just need to pause and resume a thread programmatically. I will try to use the sleep method.
That's an explanation of WHAT, not WHY. There have been many occasions where I've answered someone's question, only to discover that they shouldn't have been asking how to do it in the first place because doing something else entirely. If people would provide background to their questions then this sort of situation could be avoided and time could be saved on both sides. You thought you needed to use Thread.Suspend but that's been deprecated for reasons unbeknown to you. That suggests to me that you may not be doing things the best way. I guess we'll never know.
-
May 2nd, 2007, 12:17 AM
#5
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2005] Pausing a thread
Prefix has no suffix, but suffix has a prefix.
-
Jun 29th, 2007, 12:55 PM
#6
Addicted Member
Re: [RESOLVED] [2005] Pausing a thread
Well I'm in this same boat I think. I have a read thread that while the channel is open, it keeps listening. When I close the channel, I call mythread.abort(). But when I reopen, and send a message, it gets the message ok, but the first one always hits my Catch ex giving an error about "Thread was tryng to abort". But then it's fine after that. The odd thing, is that I always call NEW when i make the readthread object, so I would think it would get a completely new thread.
If i use mythread.suspend, I don't get the error on re-connect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|