Hi to all,

I develop with Visual Studio 2005 and I use a PC device mounting WinCE5.0. Motherboard is X86 compatible.

I need to run a "Real time" task; better i need to execute a task every 500ms; but I must be sure it run every 500ms.

If I use standard Form::Timer the task is not executed every 500ms.

The task is executed dependending on what the OS is doing.

Windows CE is a real time operative system

If YES, sombody can tell me how can I perform a real time task


Re: .NET Compact Framework Real time task on WinCE5.0 PC device


Firstly the timer you are using (System.Windows.Forms.Timer) is dependant on the windows message pump, in particular the WM_TIMER message.

To get a more accurate timer use the System.Threading.Timer class which uses a thread-pool. Be aware though that if you want to do any form updates you will need to use the Invoke/BeginInvoke method on the form.

Re: .NET Compact Framework Real time task on WinCE5.0 PC device



thanx for answer, I read the documentation regarding System.Threading.Timer class and thread-pool class but

I was not able to understand some important questions:

-System.Threading.Timer is not delayed from GC or JIT processes (better this timer is a real time timer )

-do you know the accuracy of this timer

-do you know the minimum interval (ex. 10ms) I can run the timer


Re: .NET Compact Framework Real time task on WinCE5.0 PC device

Michael Koster


Yes, Windows CE is a hard realtime capable OS.

Timers in Windows CE are 1ms accurate.

Due to the nature of managed code you cannot quaranee any timing constraints. Managed code may get delays caused by GC and/or JIT activities. This includes the System.Threading.Timer class.

The only option to competely elimitate these effects is to use native code. With this native DLL, spawn a thread that inplements the 500ms task.

Here is a sample how this may look like:

Code Snippet


HANDLE g_hThread;

bool g_bTerminate;

DWORD WINAPI ThreadProc (PVOID lpParameter)


if (!g_bTerminate)


DWORD dwStartTicks = GetTickCount ();

//Do your processing here

//calculate the sleep time (500ms - time used for processing)

DWORD dwEndTicks = GetTickCount ();

DWORD dwElapsedTime = dwEndTicks - dwStartTicks;

Sleep (500 - dwElapsedTime);


return 0;


// Call this function from managed code to start the 500ms task

__declspec (dllexport) void StartTask ()


g_bTerminate = false;

g_hThread = CreateThread (NULL, 0, ThreadProc, NULL, 0, NULL);


// Call this function from managed code to stopthe 500ms task

__declspec (dllexport) void StopTask ()


g_bTerminate = true;

WaitForSingleObject (g_hThread, INFINITE);

CloseHandle (g_hThread);


Hope this helps