国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

create and Control Windows Services--Control Your

2024-07-21 02:21:29
字體:
來源:轉載
供稿:網友

you've created your service—now it's time to create the service controller. use the system.serviceprocess namespace's servicecontroller class to interface programmatically with the service control manager to start, stop, pause, resume, and send custom commands to any installed service.

   
figure 2 | keep your service under control. click here.


connect to a service by supplying its name to the servicecontroller constructor and, optionally, specifying the machine name where the service is installed. once the servicecontroller object has been created, controlling the service is as simple as calling the start(), stop(), pause(), and continue() functions. for instance, start the service you created earlier by passing the name of the service, "file monitor service," to the servicecontroller constructor and call the start() function. if you need to retrieve the service's current status, you can compare its status property with the servicecontrollerstatus enumerated type:

servicecontroller compmon = new servicecontroller("file monitor service");
if( compmon.status == servicecontrollerstatus.running )
{
compmon.pause();
}
the service controller provided with this article might prove to be a useful utility (see the sidebar, "build the code"). once run, the service controller places an icon in the system tray. clicking on the icon brings up a popup menu that allows you to do two tasks: control a service and change the services listed (see figure 2). for the file-monitor service, you can start, stop, pause, and resume it as well as reset the performance counter data you implemented as custom service commands. you change dynamically which services are listed on the popup menu by selecting options, whose dialog lists currently installed services on the local system (see figure 3). specify the ones you want listed on the service controller menu by placing check marks next to them.

   
figure 3 | add services to the menu dynamically. click here.


use the servicecontroller class once again to get a list of services installed on the local system. the call to servicecontroller.getservices() returns an array of the service names. you can then enumerate and extract the names individually using an ienumerator interface on the array. to fill the listbox within the options dialog, you call the insertitem() method provided by the listbox control:

ienumerator ienum = servicecontroller.getservices().getenumerator();
int i = 0;
while( ienum.movenext() != false )
{
servicelist.insertitem(i,((servicecontroller) ienum.current).displayname );
    i++;
}
when the service controller is running, you can see the file-monitoring service in action (see figure 4). open the administrative tools in the control panel and double-click on performance to view the performance counter data. you must add the file-monitor performance counter to the graph manually by clicking on the toolbar's "+" button, selecting the "file monitor service" category, and adding the four file-monitor counters. notice the graphs change as a result of system use.

   
figure 4 | give a command performance. click here.


in this article, i showed you how to create windows services using .net and vc#.net. although i used a simplified example, i presented key concepts to help you get started. you should also find the service controller utility invaluable as you execute and debug your service. i think you'll find out that services aren't that difficult after all.

mark schmidt is a software engineer at hewlett-packard. when he's not busy working or writing, he enjoys trying to keep up with his three active sons. he's recently found a new love for technical writing, so you can expect even more articles in the future. e-mail mark at [email protected]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 木兰县| 延津县| 普陀区| 应城市| 福清市| 类乌齐县| 石屏县| 房产| 临颍县| 雷山县| 凤庆县| 晴隆县| 汕尾市| 长宁县| 新乡县| 建湖县| 吉林市| 芒康县| 文化| 娄底市| 洮南市| 洱源县| 凌海市| 恭城| 扎鲁特旗| 晴隆县| 长垣县| 江山市| 福建省| 永顺县| 郯城县| 洞口县| 安阳市| 南陵县| 镇坪县| 沾化县| 胶州市| 惠水县| 公安县| 连江县| 辽阳市|