473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

vb .net suspend/resume Thread

Since from .net 2.0 thread suspend/resume don't work, i have search the internet for another way for manage threads, but now i have a project with a single thread and i need to pause/resume but no method apply here.
Inside my thread is Do Loop that search the internet and show's me the results on a list box array.
I need to pause this function, and when i resume it to search from where it was, i tried many ways and one of them is Monitor Pulse.
Expand|Select|Wrap|Line Numbers
  1. Private _pause As Boolean = False
  2. Private _threadLock As New Object()
  3.  
  4.    Private Sub PauseThread()
  5.         _pause = True
  6.     End Sub
  7.  
  8.     Private Sub ResumeThread()
  9.         _pause = False
  10.         SyncLock _threadLock
  11.             Monitor.Pulse(_threadLock)
  12.         End SyncLock
  13.     End Sub
  14.  
  15.     Private Sub method(ByVal instr As String)
  16.  
  17.         Do
  18.             While True
  19.  
  20.                 If _pause = True Then
  21.                     SyncLock _threadLock
  22.                         Monitor.Wait(_threadLock)
  23.                     End SyncLock
  24.                 ElseIf _pause = False Then
  25.         'Do work    
  26.  
  27.                 End If
  28.  
  29.             End While
  30.         Loop
  31.     End Sub
My problem is when i "suspend" the thread and resume it the thread starts from beginning, the same thing apply if the search is over, same thing it starts from beginning because i put the loop at the beginning of function.
I also tried to Do Loop the "work" bu then i cannot suspend because this means the search or loop it needs to be completed for being "suspended", but the same thing apply here, if i "suspend" and "resume" it it starts from the begginging Monitor.pulse will restarts the thread, it doesn't allow to resume the thread from where it suspend.
I want to know another way that may work for my issue, please help me, Regards Yuri.
Apr 2 '12 #1
0 1666

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be...
14
by: Jiri Kripac | last post by:
Languages such as Simula 67 contain a general concept of coroutines that allow the execution of a method to be suspended without rolling back the stack and then later resumed at the same place as...
2
by: Sakharam Phapale | last post by:
Hi All, In following example, while playing file, if thread goes in WaitSleepJoin state, due to Thread.Sleep method. Now I want to suspend thread by clicking on cmdSuspend button. I have...
2
by: juky | last post by:
Hi all, I have a loop in the thread checking for a particular service status, whenever the status changes to "stopped" a RaiseEvent is generated by thread and another function runs. At the same...
6
by: Buddy Home | last post by:
Hello, I want to understand whats the best way to write code to replace Thread.Suspend, Thread.Resume and Thread.Abort. I have lots of code calling these existing methods and want to minimize...
4
by: wanwan | last post by:
I'm using Microsoft Visual Studio 2005 in multithreading, I want to be able to pause and resume a thread. I see that suspend and resume are deprecated. So what can I use instead.
3
by: =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post by:
I have a code which registers all threads with a thread dump class. At intervals this thread dump class will dump the stack trace of all threads. As calling StackTrace(threadtoDump) from a...
0
by: M.-A. Lemburg | last post by:
On 2008-11-13 02:57, scsoce wrote: I'm not sure I understand... the OS will take care of all this for you. If you want to suspend the execution of a thread you have to explicitly code for...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.