How to resume thread?

  • Thread starter Thread starter TOMERDR
  • Start date Start date
T

TOMERDR

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(Sync));
m_workerThread.Name = "Sync";
m_workerThread.IsBackground = true;
m_workerThread.Start();
}

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

}
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top