Windows系统服务 [英] Windows System services

查看:59
本文介绍了Windows系统服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

任何人都可以让我知道如何挂起Windows测试服务.
目的是模拟一些场景.

谢谢
Sudhir

Hello Friends ,

Could any one please let me know how we can hang a windows test service.
the purpose is to simulate some scenario.

Thanks
Sudhir

推荐答案

在任何事件中均使用
while(1)

.您的程序将挂起,或递归地调用任何函数.

in any of the event. Your program will hang, or call recursively any function.


while (1);

和递归函数调用都不是让程序挂起"的好主意. "while"的想法不能很好地工作,因为它以非常占用CPU的循环发送程序.有时这使得同时调试其他程序变得很困难.

递归函数调用将为堆栈分配越来越多的空间,最后以占用大量内存结束,直到堆栈的地址空间用完为止.都不是一个好主意.

为什么不简单地让线程进入睡眠状态

nor a recursive function calls are such great ideas to let your program "hang". The "while" idea does not work well as it sends your program in a very CPU intensive loop. That sometimes makes it difficult to debug other programs at the same time.

The recursive function call will allocate more and more space to the stack and finally end by using up a lot of memory until your address space for the stack is used up. Neither such a great idea.

Why don''t you simply put your thread to sleep by

while (1)
    Sleep (1000);



这样一来,Windows就会知道您的线程不想在接下来的1000毫秒内执行,而CPU可以自由地做其他事情,例如运行调试器.



That will let Windows know that your thread does not want to execute for the next 1000 milliseconds and the CPU is free to do other things, like running a debugger.


这篇关于Windows系统服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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