在服务中设置线程优先级无效 [英] Setting a thread priority in a service has no effect

查看:290
本文介绍了在服务中设置线程优先级无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows服务中设置线程优先级之前,是否还需要一些其他配置?

Is there some additional configuration needed before I can set thread priorities in a Windows service?

在我的服务中,我有几个线程,每个线程都调用CreateProcess()函数来启动外部应用程序.我想根据其他因素将线程(或进程)的优先级调整为normallower.

In my service, I have a few threads that each call the CreateProcess() function to launch an external application. I would like to adjust thread (or process) priorities to normal or lower, depending on some other factors.

问题是SetThreadPriority()函数失败,并显示错误6(无效句柄?).我传入了从PROCESS_INFORMATION::hThread获取的句柄(当然是在调用CreateProcess()之后),所以我认为该句柄应该是有效的.

The problem is that SetThreadPriority() function fails with an error 6 (invalid handle?). I'm passing in a handle obtained from PROCESS_INFORMATION::hThread (after calling the CreateProcess() of course), so I think that the handle should be valid.

我还尝试过使用SetPriorityClass()函数设置进程的优先级,这也会失败.

I've also tried setting the priority on the processes using the SetPriorityClass() function, which also fails.

该服务以本地用户身份登录.

The service is logged on as a local user.

推荐答案

也许您没有正确的访问权限? SetThreadPriority上的MSDN 说:

Maybe you don't have the correct access rights? MSDN on SetThreadPriority says:

hThread [in]线程的句柄 要设置其优先级值.

hThread [in] A handle to the thread whose priority value is to be set.

句柄必须具有 THREAD_SET_INFORMATION或 THREAD_SET_LIMITED_INFORMATION访问 正确的.有关更多信息,请参见 线程安全性和访问权限.

The handle must have the THREAD_SET_INFORMATION or THREAD_SET_LIMITED_INFORMATION access right. For more information, see Thread Security and Access Rights.

Windows Server 2003和Windows XP/2000:手柄必须具有 THREAD_SET_INFORMATION访问权限.

Windows Server 2003 and Windows XP/2000: The handle must have the THREAD_SET_INFORMATION access right.

这篇关于在服务中设置线程优先级无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆