473,786 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pause and resume a thread?

11 New Member
Hi all, I'm studying on a traffic simulation project right now. However i have problem with pausing the threads. Each car is considered as a thread in my app. When the simulation is running i want to pause it. Thread.suspend( ) method doesnt work, since i have to stop the thread from altering data. Let's say if there is a car on the road, and i click on pause button, the car should stay there.
Any ideas ?

Thanks in advance.
May 29 '12 #1
2 6857
Plater
7,872 Recognized Expert Expert
Thread.Suspend( ) is obsolete. They recomend using Monitor, Mutex, Event, or Semaphores for controlling Threads.

I've never gotten real in-depth with that stuff, so I cannot give you better advice then to look up how to use some of those classes
Jun 4 '12 #2
PsychoCoder
465 Recognized Expert Moderator Contributor
I would look into Thread.Sleep to stop the thread and Thread.Interrup t to restart it.

Hope that helps :)

NOTE: MSDN has a nice article on pausing & resuming threads.
Jun 5 '12 #3

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

Similar topics

2
1570
by: TOMERDR | last post by:
Hi, I have a sync manager class which span a thread which run a tight loop(Sync function) I would like that after the loop is finished,every 5 minutes the thread will run again I want also the ability to stop the thread in the middle of the loop Is it ok to just use a timer in the SyncManager class?
2
4316
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 time the thread is suspended. When I try to resume it from the another function I have some problems. Thank you. Juky
3
4391
by: JimJam | last post by:
Hello Peeps I have created a program in VB.NET 2003 that counts down from 7.5 hours to zero from 08:00. I have a button that starts a new countdown from 1 hour to zero whilst the first one is couting down from 7.5 hours. How do I pause that time that is counting down from 1 hour & behind a new button restart it without losing one second? I would also like the time to count down from 37 hours, but will pause after
2
1292
by: Alan T | last post by:
As the Suspend method is deprecated, what method can I use? What I want to do is when the user press the button "Cancel", it will prompt the user to confirm it he want to stop the process, I need to suspend the thread before the user choose "Yes" or "No". If he choose "Yes", I will call Thread.Abort() If he choose "No", I will call Thread.Resume().
5
2807
by: Alan T | last post by:
I will do several things in my thread: Copy a file to a location Update database record Read the file content Write the content to a log file If I call Thread.Abort(), it may be possible to stop at the middle of the something ?
6
10271
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 the risk of changing the code everywhere so here is what I think I could do, which is to create my own ThreadWrapper class which inherits from Thread and which has these three methods already defined but does it a different way and then my...
4
4612
by: fAnSKyer/C# newbie | last post by:
I am using winmm.dll and I found that I can't just suspend it and resume it? What should I do? Any better idea? Should I use thread? and thread.suspend will work? Thanks
1
2333
by: cybersurfer | last post by:
I am writing an appliaction that needs to copy files to a backup folder and then move the same files to a network share once the copying is complete. What I would like to do though is after each file is copied I's like to pause the application for a few milliseconds before the application resumes with the next copy instruction. How would I go about doing this? I have seen the timer control that is available but am quite unsure how to use it....
20
5543
by: cty0000 | last post by:
I have some question.. This is my first time to use thread.. Following code does not have error but two warring The warring is Warning 2 'System.Threading.Thread.Suspend()' is obsolete: 'Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202'
0
3052
by: Petra | last post by:
Hello, I have a strange problem with Pause and Resume using a MediaElement.Clock. I implemented a MediaElement to display a video and implemented a GUI around it to make the typical Start/Stop/Pause/Resume functionality available. For one particular video I work with the clock.Controller.Resume()
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.