All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
全面接触SQL语法(5)_[SQL,Server教程]
温故知新ASP.NET,2.0(C#)(2),-,Themes(主题)_[Asp.Net教程]
菜鸟的最爱,.NET经典代码汇总(二)_.net资料_编程技术
两台Sql,server数据同步_[SQL,Server教程]
ASP.NET2.0的缓存技术简介_[Asp.Net教程]
在GridView中实现数据并列显示_[Asp.Net教程]
PHP实现简单线性回归之数学库的重要性_php资料_编程技术
visual c++建立工具栏资源
SQL数据操作基础(中级)8_mssql学习_编程技术
小结:MYSQL数据库常用字符处理函数_php资料_编程技术
Reading number is top 10 pictures
泳装名模阿尔贝特妮写真2
Sora aoi calligraphy show
So beauty, will let you spray blood3
Born After 90 Beijing sports university campus flower photos5
A man's favorite things1
Female model behind the bitterness, often being overcharged3
The money of more than 100 countries and regions4
Summer is most suitable for young people to travel in China10
The terra-cotta warriors2
日本小萝莉2
Download software ranking
VeryCD电驴(EasyMule) V1.1.9 Build09081
Unix video tutorial14
Popkart Cracked versions Mobile phone games
Tram sex maniac 2 (H) rar bag13
Unix video tutorial4
Boxer's Top ten classic battle9
Unix video tutorial19
Twenty piece of palm leaf
塘西风月痕
传奇私服架设教程
qq published in(发表于) 2014/7/11 9:18:01 Edit(编辑)
C#中ServiceController组件应用实例

C#中ServiceController组件应用实例

C#中ServiceController组件应用实例

ServiceController组件

1.功能

ServiceController组件实际上将操作请求传递给服务控制管理器,而不是传递给服务本身。服务控制管理器停止、启动或暂停服务,或者执行其他指定的操作。ServiceController 将请求传递给服务控制管理器后返回,而不等待服务控制管理器将请求传递给服务。因此,应该在服务类自身而不是在ServiceController类中处理异常。图1所示为Service Controller组件。



图1 ServiceController组件

2.属性

ServiceController组件常用属性及说明如表1所示。



表1 ServiceController组件常用属性及说明

下面对比较重要的属性进行详细介绍。

(1)CanStop属性,该属性用于获取一个值,该值指示服务在启动后是否可以停止。

语法:

public bool CanStop { get;}
属性值:如果服务可以停止则为True;否则为False。

(2)ServiceName属性。获取或设置对此实例引用的服务进行标识的名称。

语法:

public string ServiceName { get; set; }
属性值:对此ServiceController实例引用的服务进行标识的名称。默认值为空字符串("")。

示例

CanStop属性和ServiceName属性的使用

本示例实现的是当程序运行时单击【CanStop属性】按钮,通过CanStop属性的返回值,来判断名为“IISAdmin”的服务是否可以开始或停止,示例运行结果如图2所示。



图2 IISAdmin服务

程序主要代码如下:

this.serviceController1.MachineName = ".";

this.serviceController1.ServiceName = "IISAdmin";

if (serviceController1.CanStop)

{

MessageBox.Show(serviceController1.DisplayName + "服务可以停止");

}

else

{

MessageBox.Show(serviceController1.DisplayName + " 服务不可以停止");

}

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_32

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmServiceControlle());

}

}

}

★★★★★frmServiceControlle窗体设计文件完整程序代码★★★★★


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.