Setting a thread priority in a service has no effect [closed]

别说谁变了你拦得住时间么 提交于 2019-12-01 09:40:23

问题


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

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.

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.

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.


回答1:


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

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

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 and Windows XP/2000: The handle must have the THREAD_SET_INFORMATION access right.



来源:https://stackoverflow.com/questions/239160/setting-a-thread-priority-in-a-service-has-no-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!