KeDelayExecutionThread not working?

I have created a system thread in my driver, which I believe is always running at passive level,
and in it I am trying to do a simple delay of 500 ms using KeDelayExecutionThread().
It does not seem to be working for me. I get no build errors or run-time errors, but the
call just seems to return right away. I am getting back STATUS_SUCCESS from all my calls to
KeDelayExecutionThread(), but as I said, it does not seem to be delaying, just returning immediately.

Any ideas? Code snippet shown below.

Thanks,
Don

NTSTATUS status;
LARGE_INTEGER Timeout; /* Units of 100 ns */
int WriteDelay = 5000; /* delay is 500 ms */

Timeout.HighPart = 0;
Timeout.LowPart = (DWORD)WriteDelay;

MyKdPrint ((“Write Delay = %d\n”, WriteDelay));

status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);

switch( status )
{
case STATUS_SUCCESS:
{
MyKdPrint ((“STATUS_SUCCESS\n”));
break;
}
case STATUS_ALERTED:
{
MyKdPrint ((“STATUS_ALERTED\n”));
break;
}
case STATUS_USER_APC:
{
MyKdPrint ((“STATUS_USER_APC\n”));
break;
}
default:
{
MyKdPrint ((“STATUS_unknown\n”));
break;
}
}

> int WriteDelay = 5000; /* delay is 500 ms */
Try to change the sign (5000 => -5000).
Positives are absolute delays, negatives are relative (to the current time).
Like:

#define MILLISECOND 10000 // 100 nanosecs * 10,000 = 1 ms
#define RELATIVE_MILLISECOND (-MILLISECOND) // minus means relative time
timeout.QuadPart = RELATIVE_MILLISECOND;
timeout.QuadPart *= msecsToWait;

----- Original Message -----
From: “Don Matthews”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Wednesday, August 16, 2006 9:24 AM
Subject: [ntdev] KeDelayExecutionThread not working?

>
> I have created a system thread in my driver, which I believe is always
> running at passive level,
> and in it I am trying to do a simple delay of 500 ms using
> KeDelayExecutionThread().
> It does not seem to be working for me. I get no build errors or run-time
> errors, but the
> call just seems to return right away. I am getting back STATUS_SUCCESS
> from all my calls to
> KeDelayExecutionThread(), but as I said, it does not seem to be delaying,
> just returning immediately.
>
> Any ideas? Code snippet shown below.
>
> Thanks,
> Don
>
>
> NTSTATUS status;
> LARGE_INTEGER Timeout; /* Units of 100 ns /
> int WriteDelay = 5000; /
delay is 500 ms */
>
> Timeout.HighPart = 0;
> Timeout.LowPart = (DWORD)WriteDelay;
>
> MyKdPrint ((“Write Delay = %d\n”, WriteDelay));
>
> status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);
>
> switch( status )
> {
> case STATUS_SUCCESS:
> {
> MyKdPrint ((“STATUS_SUCCESS\n”));
> break;
> }
> case STATUS_ALERTED:
> {
> MyKdPrint ((“STATUS_ALERTED\n”));
> break;
> }
> case STATUS_USER_APC:
> {
> MyKdPrint ((“STATUS_USER_APC\n”));
> break;
> }
> default:
> {
> MyKdPrint ((“STATUS_unknown\n”));
> break;
> }
> }
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

Well you are delaying to a half a millsecond after midnight in 1601 so the
delay is complete.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Don Matthews” wrote in message news:xxxxx@ntdev…
>
> I have created a system thread in my driver, which I believe is always
> running at passive level,
> and in it I am trying to do a simple delay of 500 ms using
> KeDelayExecutionThread().
> It does not seem to be working for me. I get no build errors or run-time
> errors, but the
> call just seems to return right away. I am getting back STATUS_SUCCESS
> from all my calls to
> KeDelayExecutionThread(), but as I said, it does not seem to be delaying,
> just returning immediately.
>
> Any ideas? Code snippet shown below.
>
> Thanks,
> Don
>
>
> NTSTATUS status;
> LARGE_INTEGER Timeout; /* Units of 100 ns /
> int WriteDelay = 5000; /
delay is 500 ms */
>
> Timeout.HighPart = 0;
> Timeout.LowPart = (DWORD)WriteDelay;
>
> MyKdPrint ((“Write Delay = %d\n”, WriteDelay));
>
> status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);
>
> switch( status )
> {
> case STATUS_SUCCESS:
> {
> MyKdPrint ((“STATUS_SUCCESS\n”));
> break;
> }
> case STATUS_ALERTED:
> {
> MyKdPrint ((“STATUS_ALERTED\n”));
> break;
> }
> case STATUS_USER_APC:
> {
> MyKdPrint ((“STATUS_USER_APC\n”));
> break;
> }
> default:
> {
> MyKdPrint ((“STATUS_unknown\n”));
> break;
> }
> }
>
>
>

This is a common mistake.

For a relative time (delay), you need to specify a negative value for the
timeout. A positive value means to wait until the specified time (since the
epoch) has been reached. Of course, 5000 is only 500ms since the epoch,
which occurred long ago, so it returns right away.

So making your timeout -5000 will give you a 500ms delay.

At 06:24 AM 8/16/2006, you wrote:

I have created a system thread in my driver, which I believe is always
running at passive level,
and in it I am trying to do a simple delay of 500 ms using
KeDelayExecutionThread().
It does not seem to be working for me. I get no build errors or run-time
errors, but the
call just seems to return right away. I am getting back STATUS_SUCCESS
from all my calls to
KeDelayExecutionThread(), but as I said, it does not seem to be delaying,
just returning immediately.

Any ideas? Code snippet shown below.

Thanks,
Don

NTSTATUS status;
LARGE_INTEGER Timeout; /* Units of 100 ns */
int WriteDelay = 5000; /* delay is 500 ms */

Timeout.HighPart = 0;
Timeout.LowPart = (DWORD)WriteDelay;

MyKdPrint ((“Write Delay = %d\n”, WriteDelay));

status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);

switch( status )
{
case STATUS_SUCCESS:
{
MyKdPrint ((“STATUS_SUCCESS\n”));
break;
}
case STATUS_ALERTED:
{
MyKdPrint ((“STATUS_ALERTED\n”));
break;
}
case STATUS_USER_APC:
{
MyKdPrint ((“STATUS_USER_APC\n”));
break;
}
default:
{
MyKdPrint ((“STATUS_unknown\n”));
break;
}
}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Russ Poffenberger
Credence Systems Corp.
xxxxx@credence.com

Thanks! You also pointed me to another problem I was having with the granularity. The delay value I was using (5000) would only
give a delay of 500 us, not 500 ms.

“sh_alex” wrote in message news:xxxxx@ntdev…
>> int WriteDelay = 5000; /* delay is 500 ms */
> Try to change the sign (5000 => -5000).
> Positives are absolute delays, negatives are relative (to the current time).
> Like:
>
> #define MILLISECOND 10000 // 100 nanosecs * 10,000 = 1 ms
> #define RELATIVE_MILLISECOND (-MILLISECOND) // minus means relative time
> timeout.QuadPart = RELATIVE_MILLISECOND;
> timeout.QuadPart = msecsToWait;
>
> ----- Original Message -----
> From: “Don Matthews”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, August 16, 2006 9:24 AM
> Subject: [ntdev] KeDelayExecutionThread not working?
>
>
>>
>> I have created a system thread in my driver, which I believe is always running at passive level,
>> and in it I am trying to do a simple delay of 500 ms using KeDelayExecutionThread().
>> It does not seem to be working for me. I get no build errors or run-time errors, but the
>> call just seems to return right away. I am getting back STATUS_SUCCESS from all my calls to
>> KeDelayExecutionThread(), but as I said, it does not seem to be delaying, just returning immediately.
>>
>> Any ideas? Code snippet shown below.
>>
>> Thanks,
>> Don
>>
>>
>> NTSTATUS status;
>> LARGE_INTEGER Timeout; /
Units of 100 ns /
>> int WriteDelay = 5000; /
delay is 500 ms */
>>
>> Timeout.HighPart = 0;
>> Timeout.LowPart = (DWORD)WriteDelay;
>>
>> MyKdPrint ((“Write Delay = %d\n”, WriteDelay));
>>
>> status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);
>>
>> switch( status )
>> {
>> case STATUS_SUCCESS:
>> {
>> MyKdPrint ((“STATUS_SUCCESS\n”));
>> break;
>> }
>> case STATUS_ALERTED:
>> {
>> MyKdPrint ((“STATUS_ALERTED\n”));
>> break;
>> }
>> case STATUS_USER_APC:
>> {
>> MyKdPrint ((“STATUS_USER_APC\n”));
>> break;
>> }
>> default:
>> {
>> MyKdPrint ((“STATUS_unknown\n”));
>> break;
>> }
>> }
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>
>

To make your your life easier in the future:
http://www.osronline.com/article.cfm?article=261

-scott


Scott Noone
Software Engineer
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Don Matthews” wrote in message news:xxxxx@ntdev…
> Thanks! You also pointed me to another problem I was having with the
> granularity. The delay value I was using (5000) would only give a delay
> of 500 us, not 500 ms.
>
>
>
> “sh_alex” wrote in message news:xxxxx@ntdev…
>>> int WriteDelay = 5000; /* delay is 500 ms */
>> Try to change the sign (5000 => -5000).
>> Positives are absolute delays, negatives are relative (to the current
>> time).
>> Like:
>>
>> #define MILLISECOND 10000 // 100 nanosecs * 10,000 = 1 ms
>> #define RELATIVE_MILLISECOND (-MILLISECOND) // minus means relative
>> time
>> timeout.QuadPart = RELATIVE_MILLISECOND;
>> timeout.QuadPart = msecsToWait;
>>
>> ----- Original Message -----
>> From: “Don Matthews”
>> Newsgroups: ntdev
>> To: “Windows System Software Devs Interest List”
>> Sent: Wednesday, August 16, 2006 9:24 AM
>> Subject: [ntdev] KeDelayExecutionThread not working?
>>
>>
>>>
>>> I have created a system thread in my driver, which I believe is always
>>> running at passive level,
>>> and in it I am trying to do a simple delay of 500 ms using
>>> KeDelayExecutionThread().
>>> It does not seem to be working for me. I get no build errors or
>>> run-time errors, but the
>>> call just seems to return right away. I am getting back STATUS_SUCCESS
>>> from all my calls to
>>> KeDelayExecutionThread(), but as I said, it does not seem to be
>>> delaying, just returning immediately.
>>>
>>> Any ideas? Code snippet shown below.
>>>
>>> Thanks,
>>> Don
>>>
>>>
>>> NTSTATUS status;
>>> LARGE_INTEGER Timeout; /
Units of 100 ns /
>>> int WriteDelay = 5000; /
delay is 500 ms */
>>>
>>> Timeout.HighPart = 0;
>>> Timeout.LowPart = (DWORD)WriteDelay;
>>>
>>> MyKdPrint ((“Write Delay = %d\n”, WriteDelay));
>>>
>>> status = KeDelayExecutionThread (KernelMode, FALSE, &Timeout);
>>>
>>> switch( status )
>>> {
>>> case STATUS_SUCCESS:
>>> {
>>> MyKdPrint ((“STATUS_SUCCESS\n”));
>>> break;
>>> }
>>> case STATUS_ALERTED:
>>> {
>>> MyKdPrint ((“STATUS_ALERTED\n”));
>>> break;
>>> }
>>> case STATUS_USER_APC:
>>> {
>>> MyKdPrint ((“STATUS_USER_APC\n”));
>>> break;
>>> }
>>> default:
>>> {
>>> MyKdPrint ((“STATUS_unknown\n”));
>>> break;
>>> }
>>> }
>>>
>>>
>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>
>
>