Click here to Skip to main content
16,006,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Generating a short delay (a few ms) Pin
LittleYellowBird4-Nov-02 3:02
LittleYellowBird4-Nov-02 3:02 
GeneralRe: Generating a short delay (a few ms) Pin
includeh104-Nov-02 1:10
includeh104-Nov-02 1:10 
GeneralRe: Generating a short delay (a few ms) Pin
LittleYellowBird4-Nov-02 2:10
LittleYellowBird4-Nov-02 2:10 
GeneralRe: Generating a short delay (a few ms) Pin
includeh104-Nov-02 2:25
includeh104-Nov-02 2:25 
GeneralRe: Generating a short delay (a few ms) Pin
LittleYellowBird4-Nov-02 3:09
LittleYellowBird4-Nov-02 3:09 
GeneralRe: Generating a short delay (a few ms) Pin
includeh104-Nov-02 4:26
includeh104-Nov-02 4:26 
GeneralRe: Generating a short delay (a few ms) Pin
LittleYellowBird5-Nov-02 3:18
LittleYellowBird5-Nov-02 3:18 
GeneralRe: Generating a short delay (a few ms) Pin
Roger Allen4-Nov-02 7:09
Roger Allen4-Nov-02 7:09 
I did something similar for a data collection thread that has to get spectra from a Diode array detector on set intervals. The way I did it was to the set thread priority very high (TIME_CRITICAL), so when the Sleep() completed, that thread was given control again. As it spent most of its time in a sleep() state it did not have any adverse effect of system performance.

Some of the oce envolved was:

RunThread->SetThreadPriority(THREAD_PRIORITY_TIME_CRITICAL) ;


	FILETIME time1;
	FILETIME time2;


	::GetSystemTimeAsFileTime(&time1) ;		// get the current time
	
	while (...)
		{
		::GetSystemTimeAsFileTime(&time2) ;		// get the current time
		delay = (m_spectra_frequency * spectra_collected) - CalculateElapsedTime(&time1, &time2) ;
		if (delay >= 0.001)
			Sleep((unsigned long)(delay * 1000.0)) ;
		}




double CalculateElapsedTime(FILETIME *start, FILETIME *current)
{
	double	elapsed_time ;
	__int64	st ;
	__int64	ct ;
	__int32	*p ;

	p = (__int32*)&st ;
	*p++ = start->dwLowDateTime ;
	*p = start->dwHighDateTime ;
	//st = (start->dwHighDateTime << 32) + start->dwLowDateTime ;
	p = (__int32*)&ct ;
	*p++ = current->dwLowDateTime ;
	*p = current->dwHighDateTime ;
	//ct = (current->dwHighDateTime << 32) + current->dwLowDateTime ;
	elapsed_time = (double)(ct - st) ;
	elapsed_time /= 10000000.0 ;	// convert from 100ns intervals to seconds
	return elapsed_time ;
}


It may be of use


Roger Allen
Sonork 100.10016

I have a terminal disease. Its called life!
GeneralRe: Generating a short delay (a few ms) Pin
LittleYellowBird5-Nov-02 3:29
LittleYellowBird5-Nov-02 3:29 
GeneralChange data format from CString to int Pin
ooosawaddee33-Nov-02 23:35
ooosawaddee33-Nov-02 23:35 
GeneralRe: Change data format from CString to int Pin
ian mariano3-Nov-02 23:43
ian mariano3-Nov-02 23:43 
GeneralRe: Change data format from CString to int Pin
RChin3-Nov-02 23:48
RChin3-Nov-02 23:48 
GeneralMSI files problem Pin
Anthony B.3-Nov-02 23:25
Anthony B.3-Nov-02 23:25 
GeneralRe: MSI files problem Pin
ian mariano3-Nov-02 23:33
ian mariano3-Nov-02 23:33 
GeneralRe: MSI files problem Pin
Anonymous6-Nov-02 12:53
Anonymous6-Nov-02 12:53 
GeneralComparing VC++.net standard and VS.net professional Pin
Anonymous3-Nov-02 23:30
Anonymous3-Nov-02 23:30 
General/MD and other c/c++ code generation options Pin
Mondrianx3-Nov-02 23:00
sussMondrianx3-Nov-02 23:00 
GeneralRe: /MD and other c/c++ code generation options Pin
Stephane Rodriguez.5-Nov-02 2:34
Stephane Rodriguez.5-Nov-02 2:34 
GeneralOutlook address Book invoking in VC6 Pin
Sufiyan Sana3-Nov-02 21:57
Sufiyan Sana3-Nov-02 21:57 
GeneralRe: Outlook address Book invoking in VC6 Pin
ian mariano3-Nov-02 23:49
ian mariano3-Nov-02 23:49 
GeneralRe: Outlook address Book invoking in VC6 Pin
Anonymous4-Nov-02 0:02
Anonymous4-Nov-02 0:02 
GeneralRe: Outlook address Book invoking in VC6 Pin
ian mariano4-Nov-02 6:51
ian mariano4-Nov-02 6:51 
GeneralRe: Outlook address Book invoking in VC6 Pin
Michael P Butler4-Nov-02 1:08
Michael P Butler4-Nov-02 1:08 
GeneralGDI+ linker issues Pin
Senkwe Chanda3-Nov-02 20:26
Senkwe Chanda3-Nov-02 20:26 
GeneralRe: GDI+ linker issues Pin
Shog93-Nov-02 21:26
sitebuilderShog93-Nov-02 21:26 

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.