Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i started to learn about driver programming

i want to make my driver do a thing every 2000 ms for example

and in c++ i will be like this
C++
while(true){
Sleep(2000);//(2 Seconds)
DoSomething();
}


the question is :
how to do like it in c driver
it must be like this
C++
while(1)
{
SleepFunction(2000);//Which doesnt exist
DoSomething();
}
Posted
Comments
xXTariqoO 4-Aug-13 19:27pm    
i prefer to use it in new thread

The principle is exactly the same as creating delays in user mode. Sleep() has very limited value and you can use Google to find out why. Ultimately you need waitable timers.

(1) Create a kernel timer via KeInitializeTimer.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff552168(v=vs.85).aspx

(2) Set the timer with KeSetTimerEx and use a period of 2s for example.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff553292(v=vs.85).aspx

(3) Create a thread in your driver. In the thread, call KeWaitForSingleObject to wait on the timer.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff553350(v=vs.85).aspx
See also:


http://www-user.tu-chemnitz.de/~heha/oney_wdm/ch04e.htm

http://www.techtalkz.com/microsoft-device-drivers/245779-kesettimer-expiration.html


After that refer to Google.
 
Share this answer
 
v2
Also you can use KeDelayExcutionThread

Third parameter of this function is in 100 nano seconds(0.01 micro seconds)

http://msdn.microsoft.com/en-us/library/windows/hardware/ff551986%28v=vs.85%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900