国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
Mastering Windows Services

Mastering Windows Services

By Altaf Al-Amin |2 Apr 2006
This is aseries of articles in which we will explore and understand thearchitecture, working, installation, maintenance and issues of Windowsservices.

Is your email address OK?You are signed up for our newsletters but your email address has not been reconfirmed in along time. To make this warning go away please clickhere to have aconfirmation email sent so we can confirm your email address and continue sending you yournewsletters. Alternatively, you canupdate your subscriptions.

Introduction

I know there are a number of articles on the Internet that talk about Windows Services, but unfortunately I didn't find any of the articles which we can call a complete Guide to Windows services. This made me come up with this series of articles.

In this series, we will explore and understand the architecture, working, installation, maintenance and issues of Windows services.

Before starting this article, let me present the whole outline which we are going to follow:

  • What is Windows service?
  • Windows service architecture
  • Namespace
  • Types of Windows service
  • States of Windows service
  • Programming model of Windows service
  • Creating Windows service
  • Installing, Uninstalling Windows service
  • Controlling Windows Service
  • Default properties of Windows service
  • Security Context of Windows Service

What is a Windows Service?

Windows services enable you toperform tasks that execute as different background processes. Itexecutes in its own process space until a user stops it or computershuts down. This kind of application does not have a user interface. Itis installed in the registry as an executable object.

Windows Service Architecture

Now let’s have a look at the Windows service architecture. The Windows service architecture consists of three components:

Service Application

An application that consists of one or more services that provides the desired functionality.

Service Controller Application

An application that enables you to control the behavior of a service.

Service Control Manager

A utility that enables you to control the services that are installed on a computer.

Namespace

The System.ServiceProcess namespace contains classes that enable you to create, install, implement and control Windows service. After you create Windows services, you use ServiceInstaller and ServiceProcessInstaller classes to install Windows service. You can view all the registered service applications in the Windows registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services .

Types of Windows Services

Windows services can be categorized on the basis of number of services running in process space. The service that uses a single process space is called Win32OwnProcess service, whereas the services that share a process with other services are called win32ShareProcess services.

States of Windows Services

The Windows services can be either in start, stop, paused and continue states. In addition, the services can be in pending state. A pending state indicates that a command was issued but not completed.

Programming Model of Windows Service Applications

You create a Windows service application by using the classes of the System.ServiceProcess namespace.

ServiceBase

You override the methods in the ServiceBase class to create services. The methods of this class enable you to specify the behavior of your service application.

ServiceProcessInstaller and ServiceInstaller

These classes enable you to define the process of installing and uninstalling your service application.

ServiceController

The methods of this class enable you to manipulate the behavior of your service. You can use its methods to start, stop and control service.

Creating Windows Service

To create a Windows service, you create a class that extends the System.ServiceProcess.ServiceBase class. You override the functions of ServiceBase to customize the behavior of your service application.

Collapse
public class DBWriter : System.ServiceProcess.ServiceBase 

I am summarizing these methods as follows:

OnStart

You override this method to specify the tasks your service performs when it starts. You can set your service to start when the computer on which it is installed reboots. To do this, you set the StartType property of the service. You use the members of the servicestartmode enumeration to define whether the service automatically starts when the computer starts, starts when a user manually starts it or is disabled.

Collapse
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
//Create Transaction File and Close it
FileStream fsTramsaction = File.Create ("c:\\Transaction.tmp");
fsTramsaction.Close();

//Create Customers DB File if it does not Exist
if (! File.Exists("c:\\customers.db"))
{
FileStream fsCustomers = File.Create ("c:\\customers.db");
fsCustomers.Close();
}
//Write to Transaction Log
myLog.WriteEntry("DBWriter Service Started Successfully on " +
System.DateTime.Now.ToString() , EventLogEntryType.Information );
}

Onpause

You override this method to specify the tasks your service performs when it pauses.

Onstop

You override this method to specify the tasks your service performs when it stops. When the stop event occurs, the service control manager checks the value of the CanStop property and passes the Stop command to the onstop method on the basis of its value.

Collapse
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// Delete the Transaction.tmp File
File.Delete("c:\\Transaction.tmp");

//Set the Performance Counter value to 0
this.myPerformanceCounter.RawValue = 0;

//Write Entry to Event Log
this.myLog.WriteEntry("Service Stopped Successfully on " + DateTime.Now ,
EventLogEntryType.Information);
}

OnContinue

You override this method to specify how your service behaves when it restarts after pausing.

OnShutDown

You override this method to specify the tasks your service performs when computer is running on shuts down.

OnCustomCommand

You override this method when you want a service to accept custom commands. The method takes an integer parameter on the basis of which a particular action is taken.

Collapse
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand (command);
switch (command)
{
case(201) : Commit();break;
case (200) : RollBack();break;
}
}

OnPowerEvent

You override this method to specify how your service performs when it receives a power management event such as low battery.

In the next article, we will see how to Install and Uninstall Windows service, and Control Windows Service. We will also explore the security contexts of this type of application.

History

  • 2nd April, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Windows服務(wù)創(chuàng)建及安裝
C#的發(fā)展歷程及應(yīng)用范圍
J2EE與.NET比較分析白皮書
An Introduction to Virtualization
Cloud Programming Concepts
Chapter 1. B. Solution Architecture: Loose Coupling with CAB
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服