473,799 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resume thread?


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?

Thanks in advance
public class SyncManager
{
Thread m_workerThread;

public SyncManager()
{

}
/// <summary>
///
/// </summary>
public Stop()
{

}

/// <summary>
///
/// </summary>
public void Start()
{
m_workerThread= new Thread(new ThreadStart(Syn c));
m_workerThread. Name = "Sync";
m_workerThread. IsBackground = true;
m_workerThread. Start();
}

/// <summary>
///
/// </summary>
public void Sync()
{

}

Nov 17 '05 #1
2 1570
Are you talking about a Timer control? You don't need a form to create
a Timer class. So there is no real reason why you cannot use a Timer
control.

HTH,
Johann Blake

Nov 17 '05 #2
TOMERDR,

You could use a timer which will re-start the process five minutes after
it ends. As for the ability to stop your loop, you could have a flag that
is set on your SyncManager class (or a method), which will cancel the loop.
This will set a flag that is checked in your thread (make sure you lock
access to the flag), and if the flag is true, it stops processing the loop.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"TOMERDR" <to*****@hotmai l.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

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?

Thanks in advance
public class SyncManager
{
Thread m_workerThread;

public SyncManager()
{

}
/// <summary>
///
/// </summary>
public Stop()
{

}

/// <summary>
///
/// </summary>
public void Start()
{
m_workerThread= new Thread(new ThreadStart(Syn c));
m_workerThread. Name = "Sync";
m_workerThread. IsBackground = true;
m_workerThread. Start();
}

/// <summary>
///
/// </summary>
public void Sync()
{

}

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2778
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 halted. If a socket is no longer in the configuration, that thread must be aborted and the socket must be closed. After the configuration is complete, the remaining threads must be resumed. I currently have the following architecture:
2
2517
by: SpookyET | last post by:
How do you pause and resume some work without using Thread.Suspend and Thread.Resume since they are deprecated in .NET 2.0?
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
17
5673
by: Benny Raymond | last post by:
I have a thread that sleeps for 5 minutes once it's finished running a method and then it repeats itself if it's supposed to (bool = true). Prior to 2.0 I was able to resume the thread after marking the bool to false which would cause the thread to finish what it was doing and complete, or to wake up for it's sleep state and not loop back into itself anymore. How do we tell a thread to stop sleeping now that Thread.Resume is obsolete?
4
2124
by: Tam | last post by:
Hi group, Just downloaded the new Visual Studio 2005 (well new to me seeing as i was previously using 2003). My problem/question is that my Thread.Resume statements in an application I've created has been depracted and I'm having trouble finding what I should use instead. Help?
6
10273
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
3202
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.
4
4613
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
3
6061
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 different thread other than the treadToDump the threadToDump must be suspended otherwise a ThreadStateException gets thrown. However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been marked as obsolete with reference to better methods of...
1
4087
by: Mike Fellows | last post by:
Having not used threads for such a long time in vb.net I have found myself in need of them I have a thread that runs and retirieves live data from a SQL database, this is running fine and has been doing its job for a long time the problem is I need to suspend this thread when a checkbox is clicked (as the data is no longer required) but when the checkbox is unclicked it needs to restart
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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,...
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
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...
1
7565
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
5463
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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.