Click here to Skip to main content
16,005,121 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to activate some choosen thread? Pin
Alexander M.,18-Aug-03 2:05
Alexander M.,18-Aug-03 2:05 
AnswerRe: How to activate some choosen thread? Pin
jhwurmbach18-Aug-03 2:34
jhwurmbach18-Aug-03 2:34 
GeneralRe: How to activate some choosen thread? Pin
vgrigor18-Aug-03 3:26
vgrigor18-Aug-03 3:26 
GeneralRe: How to activate some choosen thread? Pin
jhwurmbach18-Aug-03 4:08
jhwurmbach18-Aug-03 4:08 
GeneralRe: How to activate some choosen thread? Pin
vgrigor18-Aug-03 4:13
vgrigor18-Aug-03 4:13 
GeneralRe: How to activate some choosen thread? Pin
jhwurmbach18-Aug-03 4:35
jhwurmbach18-Aug-03 4:35 
GeneralRe: How to activate some choosen thread? Pin
vgrigor18-Aug-03 4:43
vgrigor18-Aug-03 4:43 
AnswerRe: How to activate some choosen thread? Pin
Mike Ellertson19-Aug-03 11:20
sussMike Ellertson19-Aug-03 11:20 
I used SetTimer() right before I call SuspendThread() to make the function sleep.
void CSleeperThread::run()
{
	UINT_PTR pTimer = SetTimer(NULL, NULL, job.Schedule.GetNextRunTime(), TimerProc );

	// suspend until the timer expires
	SuspendThread();

	// the timer has expired, time to run the backup job
        // **** do something
}

In SuspendThread() I pass a call back function called ThreadProc().

I've implemented ThreadProc() I use ResumeThread() and KillTimer() like so:

void CSleeperThread::TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	::EnterCriticalSection(&lock);
	
		KillTimer(NULL, idEvent); // kill the timer so it won't fire again

		if(idEvent == pTimer)
			ResumeThread();				// resume the main thread function

	::LeaveCriticalSection(&lock);
}


I used critical sections because in my class there's a possiblity that ThreadProc could be called again, before it's finished processing the first time. It may be overkill, I haven't tested that part yet.

Mike Ellertson
GeneralRe: How to activate some choosen thread? Pin
vgrigor19-Aug-03 21:02
vgrigor19-Aug-03 21:02 
GeneralRe: How to activate some choosen thread? Pin
Mikey_E20-Aug-03 7:44
professionalMikey_E20-Aug-03 7:44 
GeneralRe: How to activate some choosen thread? Pin
vgrigor20-Aug-03 20:32
vgrigor20-Aug-03 20:32 
Generalhelp with a TCP Program that sends messages Pin
Jay Hova18-Aug-03 1:55
Jay Hova18-Aug-03 1:55 
GeneralRe: help with a TCP Program that sends messages Pin
Alexander M.,18-Aug-03 1:58
Alexander M.,18-Aug-03 1:58 
GeneralRe: help with a TCP Program that sends messages Pin
Jay Hova18-Aug-03 2:04
Jay Hova18-Aug-03 2:04 
GeneralRe: help with a TCP Program that sends messages Pin
Alexander M.,18-Aug-03 2:07
Alexander M.,18-Aug-03 2:07 
GeneralRe: help with a TCP Program that sends messages Pin
Jay Hova18-Aug-03 2:12
Jay Hova18-Aug-03 2:12 
GeneralRe: help with a TCP Program that sends messages Pin
Brian Delahunty18-Aug-03 2:53
Brian Delahunty18-Aug-03 2:53 
GeneralRe: help with a TCP Program that sends messages Pin
Jay Hova18-Aug-03 3:14
Jay Hova18-Aug-03 3:14 
GeneralRe: help with a TCP Program that sends messages Pin
Brian Delahunty18-Aug-03 3:18
Brian Delahunty18-Aug-03 3:18 
GeneralNewbie: WebService,DIME, C# into C++ Pin
adaoja18-Aug-03 1:35
adaoja18-Aug-03 1:35 
GeneralScanf() in C graphic library Pin
berk_atabek18-Aug-03 1:20
berk_atabek18-Aug-03 1:20 
GeneralRe: Scanf() in C graphic library Pin
Alexander M.,18-Aug-03 2:00
Alexander M.,18-Aug-03 2:00 
GeneralMFC and std namespace-beginner question Pin
7stud18-Aug-03 0:42
7stud18-Aug-03 0:42 
GeneralRe: MFC and std namespace-beginner question Pin
Alexandru Savescu18-Aug-03 0:49
Alexandru Savescu18-Aug-03 0:49 
GeneralRe: MFC and std namespace-beginner question Pin
7stud18-Aug-03 1:14
7stud18-Aug-03 1:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.