This document provides guidance on creating and managing services in Delphi. It discusses how to create a new service project, implement key service events like OnStart and OnStop, and ensure the service remains running through the use of a loop. It also demonstrates how to pass service state changes to any worker threads, and how to install and uninstall the service. The full example code shows integrating all these elements into a complete Windows service application.
This document summarizes the processes of a dual cycle engine. It consists of:
1) Isentropic compression from state 1 to 2.
2) Constant volume heat addition from state 2 to 2.5.
3) Constant pressure heat addition from state 2.5 to 3.
4) Isentropic expansion from state 3 to 4.
5) Constant volume heat rejection from state 4 back to state 1.
The document also provides the thermal efficiency equation for a dual cycle and notes that the Otto cycle and Diesel cycle are special cases where specific heat addition process parameters are fixed.
This document discusses writing simple PLC ladder logic programs. It begins with an introduction presented by Dr. Steve Mackay on the key elements of ladder logic programs and examining simple programs and PLC troubleshooting. The document then covers objectives like the types of programming languages and basic and advanced programming instructions. It explains concepts like I/O lists, developing the program structure, verifying the program, and creating documentation for a PLC project. It provides examples and explanations of common ladder logic instructions like timers, counters, math functions, and program flow controls.
This document discusses key concepts in hydraulics and fluid mechanics. It defines important fluid properties like density, specific volume, viscosity, and surface tension. It describes Pascal's law and factors that influence pressure like elevation and atmospheric pressure. Key concepts in fluid flow are also summarized like Bernoulli's equation, venturi meters, orifices, and pumps. The document provides equations for calculating forces, pressure, discharge, and efficiency in hydraulic systems.
This document provides an overview of fluid power systems and hydraulics. It discusses the history and applications of fluid power, including using water wheels and windmills. The key types of fluid power systems are hydraulic and pneumatic. Hydraulic systems use high-pressure liquids like oil while pneumatic systems use compressed gases like air. The document also covers fluid properties, hydraulic components, basics of hydraulics like laminar and turbulent flow, and applications of fluid power systems in construction, mining, agriculture and more.
A hydraulic press is a mechanical machine that uses hydraulics to increase the power of a standard press. It was invented in 1795 by Joseph Braham and uses fluid mechanics to significantly increase the compression power applied through a press. The hydraulic press works by using two cylinders - a small slave cylinder where pressure is applied to compress a fluid, and a larger master cylinder where the fluid is pushed to, exerting a larger force through pressure transmission according to Pascal's law. There are various types of hydraulic presses used for different industrial applications like stamping, laminating, and metal forming.
This document provides information about various types of pumps. It discusses centrifugal pumps, rotary pumps, reciprocating pumps, and deep well pumps. It also covers pump classification, fundamental pump equations, centrifugal pump priming, positive displacement pumps, and plunger pumps. The key details covered include the operating principles of centrifugal, rotary, and reciprocating pumps. It also defines total dynamic head, fluid power, discharge, brake power, and efficiency equations.
Tubing Landing nipples in petroleum industryPE Mahmoud Jad
Â
Tubing Landing nipples in petroleum industry
# A completion component fabricated as a short section of tubular pipe with a machined internal surface that provides a seal area and a locking profile.
# Uses : 1) Plugging the tubing for: pressure testing
2) Installing flow control equipment such as: down chokes,regulators, SSVs, etc.
# Tubing Landing nipples types:
A) Seating nipple
1.Non-selective nipple (No-go landing nipple)
i. Top no go nipple
ii. Bottom no go nipple
2. Selective nipple
B) Hydraulic Landing Nipples
This curriculum vitae outlines the professional experience and qualifications of Hany Abd El Latif Osman. He has over 15 years of experience in customer service, sales, and accounting roles. His most recent role is as a supervisor in the customer operations department at Cable Network Egypt, where he is responsible for handling customer payments, reports, and technical support. He also has experience working in sales, customer service, and as an accountant for other companies. He has strong computer skills and is fluent in Arabic and English.
This document summarizes the processes of a dual cycle engine. It consists of:
1) Isentropic compression from state 1 to 2.
2) Constant volume heat addition from state 2 to 2.5.
3) Constant pressure heat addition from state 2.5 to 3.
4) Isentropic expansion from state 3 to 4.
5) Constant volume heat rejection from state 4 back to state 1.
The document also provides the thermal efficiency equation for a dual cycle and notes that the Otto cycle and Diesel cycle are special cases where specific heat addition process parameters are fixed.
This document discusses writing simple PLC ladder logic programs. It begins with an introduction presented by Dr. Steve Mackay on the key elements of ladder logic programs and examining simple programs and PLC troubleshooting. The document then covers objectives like the types of programming languages and basic and advanced programming instructions. It explains concepts like I/O lists, developing the program structure, verifying the program, and creating documentation for a PLC project. It provides examples and explanations of common ladder logic instructions like timers, counters, math functions, and program flow controls.
This document discusses key concepts in hydraulics and fluid mechanics. It defines important fluid properties like density, specific volume, viscosity, and surface tension. It describes Pascal's law and factors that influence pressure like elevation and atmospheric pressure. Key concepts in fluid flow are also summarized like Bernoulli's equation, venturi meters, orifices, and pumps. The document provides equations for calculating forces, pressure, discharge, and efficiency in hydraulic systems.
This document provides an overview of fluid power systems and hydraulics. It discusses the history and applications of fluid power, including using water wheels and windmills. The key types of fluid power systems are hydraulic and pneumatic. Hydraulic systems use high-pressure liquids like oil while pneumatic systems use compressed gases like air. The document also covers fluid properties, hydraulic components, basics of hydraulics like laminar and turbulent flow, and applications of fluid power systems in construction, mining, agriculture and more.
A hydraulic press is a mechanical machine that uses hydraulics to increase the power of a standard press. It was invented in 1795 by Joseph Braham and uses fluid mechanics to significantly increase the compression power applied through a press. The hydraulic press works by using two cylinders - a small slave cylinder where pressure is applied to compress a fluid, and a larger master cylinder where the fluid is pushed to, exerting a larger force through pressure transmission according to Pascal's law. There are various types of hydraulic presses used for different industrial applications like stamping, laminating, and metal forming.
This document provides information about various types of pumps. It discusses centrifugal pumps, rotary pumps, reciprocating pumps, and deep well pumps. It also covers pump classification, fundamental pump equations, centrifugal pump priming, positive displacement pumps, and plunger pumps. The key details covered include the operating principles of centrifugal, rotary, and reciprocating pumps. It also defines total dynamic head, fluid power, discharge, brake power, and efficiency equations.
Tubing Landing nipples in petroleum industryPE Mahmoud Jad
Â
Tubing Landing nipples in petroleum industry
# A completion component fabricated as a short section of tubular pipe with a machined internal surface that provides a seal area and a locking profile.
# Uses : 1) Plugging the tubing for: pressure testing
2) Installing flow control equipment such as: down chokes,regulators, SSVs, etc.
# Tubing Landing nipples types:
A) Seating nipple
1.Non-selective nipple (No-go landing nipple)
i. Top no go nipple
ii. Bottom no go nipple
2. Selective nipple
B) Hydraulic Landing Nipples
This curriculum vitae outlines the professional experience and qualifications of Hany Abd El Latif Osman. He has over 15 years of experience in customer service, sales, and accounting roles. His most recent role is as a supervisor in the customer operations department at Cable Network Egypt, where he is responsible for handling customer payments, reports, and technical support. He also has experience working in sales, customer service, and as an accountant for other companies. He has strong computer skills and is fluent in Arabic and English.
This document describes a student project to develop an education news portal called "Education-info" that allows users to access information about universities, colleges, admissions, exams, scholarships and careers. It provides details on the team members, objectives, features, methodologies, technologies used, screen designs, limitations and future plans for the project. The portal aims to be a centralized place for all education-related news and information to help users with their academic pursuits.
The document discusses dystopian literature and its characteristics. Dystopian literature refers to stories about unpleasant or repressed societies that are often portrayed as utopian. The main ideas in dystopian works include the use of propaganda to control citizens, restricted information and freedom, worshipping a figurehead or concept, constant surveillance, fear of the outside world, dehumanization, banning the natural world, enforcing conformity, and portraying society as a perfect utopia while hiding its flaws. These ideas are seen in the real world through examples like propaganda in political elections, restricted freedom under regimes like Hitler's and in North Korea, citizens trying to escape conflict in Syria, and questioning political systems through civil wars.
Nazi Germany from 1933 to 1945 is provided as a real-life example of a dystopian society. Adolf Hitler and the Nazis took control of Germany, propagated anti-Semitic views that the Jews were to blame for the war, and began systematically hunting down and killing Jews. Jews lived in fear of being sent to concentration camps where thousands died of malnourishment and disease. The document suggests that another country, whose control over its people and punishment of citizens who disobey resembles Nazi Germany, could also be considered dystopian.
This research article describes a novel method using high-density peptide microarrays and computational analysis to identify B-cell epitopes in patients with celiac disease. Overlapping peptide sequences from native and deamidated gliadin proteins were synthesized onto silicon wafers. Serum samples from celiac patients and controls were tested on the microarrays. Computational analysis identified distinct epitope sets that differentiated celiac patients from controls with high accuracy. The identified epitopes have potential for developing improved diagnostic tests for celiac disease.
This document discusses services in Android. It defines what a service is, describes the different types of services (started, bound, foreground), and explains the service lifecycle methods like onCreate(), onStartCommand(), and onDestroy(). It provides examples of when to use a service versus a thread, and best practices for services like using a foreground service if the user is aware of it or duplicating functionality with scheduled jobs. The document also covers new limitations on background services in Android O.
Android services allow long-running tasks to perform work in the background independently of an application's user interface. There are two main types of services: started services which can perform operations indefinitely even if the starting component is destroyed, and bound services which offer a client-server interface between a component and the service. Services must be started with startService() or bound to with bindService() and have lifecycle callback methods like onStartCommand(), onBind(), onCreate(), and onDestroy(). The IntentService class simplifies started service implementation. Bound services can expose interfaces using Binder, Messenger, or AIDL to allow inter-process communication.
The document introduces Windows services and provides best practices for creating them. It recommends creating a class library containing the core logic, a Windows Forms app for debugging, and a lightweight service wrapper. The class library handles all work and errors, supports cancellation, and provides callbacks for logging. The Windows Forms app uses the class library and outputs logs, while the service simply hosts the class library configuration-free. This architecture separates concerns and makes services easier to program, debug and deploy.
This document provides instructions for installing Tcat Server on one machine and using the Tcat Administration Console to manage and deploy applications. It outlines the steps to run the installer, start the Tcat server, log into the console, register the server with the console, manage the Tcat instance, and add a new application. It also provides a brief definition of what a connector is in relation to Mule applications.
This document discusses Android services. Some key points:
- Services run in the background without a user interface and are not bound to an activity's lifecycle. They are used for long-running or repetitive tasks like downloads or updating content.
- Services have a higher priority than inactive activities so the system is less likely to terminate them. They can also be configured to restart if terminated.
- Services are declared in the manifest and extend the Service class. They can be started with startService() and have lifecycle methods like onStartCommand(), onBind(), onCreate(), onDestroy().
- The onStartCommand() return value determines restart behavior if the service is terminated by the system.
The document discusses background tasks using worker services in .NET. It provides an overview of worker services and how to implement background tasks with them. It also covers how to create a worker service project that consumes an ASP.NET Core Web API and how to publish a worker service as a Windows Service. Demo projects are included to demonstrate these concepts.
Windows services allow applications to run in the background even when users are not logged on. The Service Control Manager (SCM) maintains a database of installed services and provides a unified way to control them. It enables administrators to customize security for each service. Services are started automatically based on their start type setting in the database. The SCM communicates with service programs to start, stop, and monitor their status.
Introduction to the .NET Access Control Servicebutest
Â
This document provides an introduction to using the Access Control Service (ACS) to secure REST web services. It describes a scenario where a weather forecasting service is modified to use ACS for access control. The exercises walk through signing up for an ACS namespace, configuring the service to validate tokens from ACS, and enabling a client to get a token from ACS and use it to call the service. The document contains instructions for completing tasks to set up the sample solution and configure ACS and the client/service.
Introduction to the .NET Access Control Servicebutest
Â
This document provides an introduction to using the Access Control Service (ACS) to secure REST web services. It describes a scenario where a weather forecasting service is modified to use ACS for access control. The exercises walk through signing up for an ACS namespace, configuring the service to validate tokens from ACS, and enabling a client to get a token from ACS and use it to call the service. The document contains instructions for completing tasks to set up the sample solution and configure ACS and the client and service.
Informatica is an ETL tool with components like the PowerCenter Designer used to create mappings. Mappings involve transformations like the Filter transformation which applies a condition to rows to filter out those that do not meet the condition, reducing the number of rows passed to the target. The document provides steps to create a mapping with a Filter transformation that loads only records from an EMP source table to a target F_EMP table where the SAL field is greater than or equal to 3000.
The document discusses automation best practices for companies. It recommends starting with simple automation that evolves over time, identifying common tasks for automation through issue tracking, and spending time automating processes for non-engineering teams. Automation should aim to make teams more self-sufficient through tools like chat interfaces that provide visibility, auditing, and enforce policies. Keeping automation interfaces simple but with detailed logging is advised.
This document provides information on Linux communication tools including wall, talk, write, mesg, and systemctl. It discusses how wall broadcasts messages to logged in users. It explains how talk and ytalk allow interactive chats between users. It covers how write sends text without email. It also discusses how mesg blocks or allows messages from other users. Finally, it provides an in-depth overview of the systemctl command for managing systemd services and units.
This document describes a student project to develop an education news portal called "Education-info" that allows users to access information about universities, colleges, admissions, exams, scholarships and careers. It provides details on the team members, objectives, features, methodologies, technologies used, screen designs, limitations and future plans for the project. The portal aims to be a centralized place for all education-related news and information to help users with their academic pursuits.
The document discusses dystopian literature and its characteristics. Dystopian literature refers to stories about unpleasant or repressed societies that are often portrayed as utopian. The main ideas in dystopian works include the use of propaganda to control citizens, restricted information and freedom, worshipping a figurehead or concept, constant surveillance, fear of the outside world, dehumanization, banning the natural world, enforcing conformity, and portraying society as a perfect utopia while hiding its flaws. These ideas are seen in the real world through examples like propaganda in political elections, restricted freedom under regimes like Hitler's and in North Korea, citizens trying to escape conflict in Syria, and questioning political systems through civil wars.
Nazi Germany from 1933 to 1945 is provided as a real-life example of a dystopian society. Adolf Hitler and the Nazis took control of Germany, propagated anti-Semitic views that the Jews were to blame for the war, and began systematically hunting down and killing Jews. Jews lived in fear of being sent to concentration camps where thousands died of malnourishment and disease. The document suggests that another country, whose control over its people and punishment of citizens who disobey resembles Nazi Germany, could also be considered dystopian.
This research article describes a novel method using high-density peptide microarrays and computational analysis to identify B-cell epitopes in patients with celiac disease. Overlapping peptide sequences from native and deamidated gliadin proteins were synthesized onto silicon wafers. Serum samples from celiac patients and controls were tested on the microarrays. Computational analysis identified distinct epitope sets that differentiated celiac patients from controls with high accuracy. The identified epitopes have potential for developing improved diagnostic tests for celiac disease.
This document discusses services in Android. It defines what a service is, describes the different types of services (started, bound, foreground), and explains the service lifecycle methods like onCreate(), onStartCommand(), and onDestroy(). It provides examples of when to use a service versus a thread, and best practices for services like using a foreground service if the user is aware of it or duplicating functionality with scheduled jobs. The document also covers new limitations on background services in Android O.
Android services allow long-running tasks to perform work in the background independently of an application's user interface. There are two main types of services: started services which can perform operations indefinitely even if the starting component is destroyed, and bound services which offer a client-server interface between a component and the service. Services must be started with startService() or bound to with bindService() and have lifecycle callback methods like onStartCommand(), onBind(), onCreate(), and onDestroy(). The IntentService class simplifies started service implementation. Bound services can expose interfaces using Binder, Messenger, or AIDL to allow inter-process communication.
The document introduces Windows services and provides best practices for creating them. It recommends creating a class library containing the core logic, a Windows Forms app for debugging, and a lightweight service wrapper. The class library handles all work and errors, supports cancellation, and provides callbacks for logging. The Windows Forms app uses the class library and outputs logs, while the service simply hosts the class library configuration-free. This architecture separates concerns and makes services easier to program, debug and deploy.
This document provides instructions for installing Tcat Server on one machine and using the Tcat Administration Console to manage and deploy applications. It outlines the steps to run the installer, start the Tcat server, log into the console, register the server with the console, manage the Tcat instance, and add a new application. It also provides a brief definition of what a connector is in relation to Mule applications.
This document discusses Android services. Some key points:
- Services run in the background without a user interface and are not bound to an activity's lifecycle. They are used for long-running or repetitive tasks like downloads or updating content.
- Services have a higher priority than inactive activities so the system is less likely to terminate them. They can also be configured to restart if terminated.
- Services are declared in the manifest and extend the Service class. They can be started with startService() and have lifecycle methods like onStartCommand(), onBind(), onCreate(), onDestroy().
- The onStartCommand() return value determines restart behavior if the service is terminated by the system.
The document discusses background tasks using worker services in .NET. It provides an overview of worker services and how to implement background tasks with them. It also covers how to create a worker service project that consumes an ASP.NET Core Web API and how to publish a worker service as a Windows Service. Demo projects are included to demonstrate these concepts.
Windows services allow applications to run in the background even when users are not logged on. The Service Control Manager (SCM) maintains a database of installed services and provides a unified way to control them. It enables administrators to customize security for each service. Services are started automatically based on their start type setting in the database. The SCM communicates with service programs to start, stop, and monitor their status.
Introduction to the .NET Access Control Servicebutest
Â
This document provides an introduction to using the Access Control Service (ACS) to secure REST web services. It describes a scenario where a weather forecasting service is modified to use ACS for access control. The exercises walk through signing up for an ACS namespace, configuring the service to validate tokens from ACS, and enabling a client to get a token from ACS and use it to call the service. The document contains instructions for completing tasks to set up the sample solution and configure ACS and the client/service.
Introduction to the .NET Access Control Servicebutest
Â
This document provides an introduction to using the Access Control Service (ACS) to secure REST web services. It describes a scenario where a weather forecasting service is modified to use ACS for access control. The exercises walk through signing up for an ACS namespace, configuring the service to validate tokens from ACS, and enabling a client to get a token from ACS and use it to call the service. The document contains instructions for completing tasks to set up the sample solution and configure ACS and the client and service.
Informatica is an ETL tool with components like the PowerCenter Designer used to create mappings. Mappings involve transformations like the Filter transformation which applies a condition to rows to filter out those that do not meet the condition, reducing the number of rows passed to the target. The document provides steps to create a mapping with a Filter transformation that loads only records from an EMP source table to a target F_EMP table where the SAL field is greater than or equal to 3000.
The document discusses automation best practices for companies. It recommends starting with simple automation that evolves over time, identifying common tasks for automation through issue tracking, and spending time automating processes for non-engineering teams. Automation should aim to make teams more self-sufficient through tools like chat interfaces that provide visibility, auditing, and enforce policies. Keeping automation interfaces simple but with detailed logging is advised.
This document provides information on Linux communication tools including wall, talk, write, mesg, and systemctl. It discusses how wall broadcasts messages to logged in users. It explains how talk and ytalk allow interactive chats between users. It covers how write sends text without email. It also discusses how mesg blocks or allows messages from other users. Finally, it provides an in-depth overview of the systemctl command for managing systemd services and units.
As everyone knows, a lot of changes made after API level 26 for optimizing Android system’s performance, the battery uses and other system-level problems which I am writing below:
1- Changes in Service. 2- Changes in Broadcast Reciever. 3- Changes in Push Notification
This document provides instructions for implementing a simple web service using Eclipse. It begins with background on web services and their components. It then discusses the top-down and bottom-up approaches to web service development. The document walks through setting up Eclipse with the necessary plugins. It provides step-by-step instructions to create a project, write the service logic, generate the web service and client, test the service, and use the client. It includes an introduction, background sections on web services and Eclipse setup, and detailed steps for creating a "Hello" web service that returns a greeting message.
Configuring an application_server_in_eclipseSupratim Ray
Â
The document provides instructions for configuring an application server in Eclipse. It describes how to view existing servers, use the New Server wizard to select and configure a Tomcat application server, specifying the install location and JRE. Once configured, the new server will appear in the Servers view and can be used to deploy and run web applications and services.
1. A service in Android is a component that runs in the background without a user interface. Services are used to perform long-running operations or to deliver notifications and other important updates while an app is not actively being used.
2. The document discusses the anatomy of an Android application and the different components - activities, services, content providers, and broadcast receivers. It provides an example service that runs in the background and displays a notification in the notification bar at periodic intervals until stopped.
3. The example creates a service class that extends Service, adds actions to buttons in an activity to start and stop the service, and uses the onStartCommand() method to display a notification at a specified time interval until the service
The document provides steps for using the debugger and profiler in NetBeans 6.0. [1] It describes setting breakpoints, stepping through code, and viewing variables to debug a simple program. [2] It then demonstrates profiling the same program to monitor execution time and memory usage. [3] Adding a line of code that creates Date objects without disposing of them showed how this could lead to memory leak issues.
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docxfelicidaddinwoodie
Â
15LLP108_Demo4_LedBlinking.pdf
1. Introduction
In Demo3, we have learned how to read sensor values of light, temperature and humidity of a node
and output these values to the console. In this demonstration, we will use the code from Demo3 and
learn how to turn on/off the LEDs and make them blinking regularly on the sensor node XM1000,
meanwhile to count how many times the LED has blinked and output the count to the console.
2. Timer
In order to make the blue LED on the XM1000 sensor node to blink in every half second (i.e. On 0.5S
and Off 0.5S), we also need a timer. Follow the instructions in Demo3 for configure and reset a timer.
We aslo need to create an infinite while() loop so that it runs our functions repeatedly, such as
counting the times the LED has blinked, output the counter’s value and actually turn on or off the
LEDs to make it blinking.
Please follow timer and while() loop structure in Demo3.
3. LED Blinking
To get access to the LED functionalities in Contiki, we need to include the LED header file in the
source code:
#include "leds.h" // file is in directory /home/user/contiki/core/dev
After the process begin, we have to initialise the LEDs on the sensor node by calling the following
function:
leds_init(); // Initialise the LEDs
And finally we can turn on, off, or blink the LEDs by the following functions:
void leds_on(unsigned char leds);
void leds_off(unsigned char leds);
void leds_toggle(unsigned char leds);
void leds_invert(unsigned char leds);
For example, if you want to blink the Blue LED, yon need to call the toggle function as:
void leds_toggle(LEDS_BLUE); // Toggle the blue LED
4. Exercise
Modify the program from Demo3 with periodic timer to make the BLUE led blinking in every half
second, also to count the blinking times and output the counted number to the console.
Can your change the code so that the BLUE LED is lighted for 1 second and off for 0.5 second
periodically?
15LLP108 – Internet of Things and Applications
Lab Session 2: Demo 4 – LED Blinking
Prepared by Xiyu Shi
5. Source code
Here is the source code for reference
#include "contiki.h"
#include "leds.h"
#include <stdio.h> /* for printf() */
static struct etimer timer;
/*____________________________________________________*/
PROCESS(led_blinking_process, "LED Blinking Process");
PROCESS(LED_process, "LED process");
AUTOSTART_PROCESSES(&LED_process);
/*____________________________________________________*/
PROCESS_THREAD(LED_process, ev, data)
{
static int count = 0;
PROCESS_BEGIN();
etimer_set(&timer, CLOCK_CONF_SECOND/2); // 0.5S timer
leds_init(); // intialise the LEDs
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER); // wait for timer event
count++; // count the blinking times
process_start(&led_blinking_process, NULL); // to blink the BLUE Led
printf("Count: %d\n", count); // output the counte ...
How to restart the RDP without rebooting the windows server .pdf
Â
Delphi - Howto Services
1. Draft: 1st
Date: 22 Jan. 08
Author: Niall Munro
Title: GS: Assistant Data Analyst
Address: Generation Scotland Office
Room D38
Medical Genetics (OPD2)
2nd Floor, Out Patients Department
Western General Hospital
Crewe Road South
Edinburgh
EH4 2XU
Email: niall.munro@ed.ac.uk
DELPHI HOWTO:
SERVICES
2. Delphi Howto: System Services
CONTENTS
Introduction 1
Creating a New Service 2
Service Events 3
Keeping it Alive 4
Passing Event Signals to Threads 5
Installing / Uninstalling Your Service 6
Full Example 7
Useful Links 9
Table 1: Service events 3
Example 1: Skeleton code 1
Example 2: Keep alive loop 4
Example 3: Passing state calls to worker threads 5
Example 4: Installing your service 6
Example 5: Service uninstall success 6
Example 6: Full example code 8
3. Delphi Howto: System Services
1 | P a g e
INTRODUCTION
A service is an application that runs in the background of an operating system that waits for client connections,
does some processing and then returns information. Web, FTP and e-mail servers are common examples of
services; they all require little human interaction hence why they run in the background. Services are also
useful for starting mission critical applications at boot time in that they start with the system instead of waiting
for a user to log on and have it automatically or manually launch at that point. This means that if there is a
systems failure and the computer the application is installed on may start upon reboot without a user having
logged on.
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr,
Dialogs;
type
TMyService = class(TService)
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;var
MyService: TMyService;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
MyService.Controller(CtrlCode);
end;
function TMyService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
end.
Example 1: Skeleton code
4. Delphi Howto: System Services
2 | P a g e
CREATING A NEW SERVICE
You can create a new Delphi service in the Borland IDE by going to File>New>Other and selecting Service. This
will create the skeleton code as seen in example 1 on the previous page as well as other service specific code
required to communicate properly with the Windows API.
Note that you are not recommended to add services to non-service applications as they will not include the
necessary additionally generated code to handle service specific errors or Windows calls.
Services have both Code and Design views so you may drag and drop components from the designer toolbox.
The easiest way to name your service is by renaming it in the designer context by changing the Name attribute
to the name you wish to give to your new service object. This is also the name the service will be known as to
the system and the DisplayName attribute will be what appears in the services console and TaskManager i.e.
Microsoft’s Internet Information Services is displayed as World Wide Web Publishing in the services console
yet its service name is W3SVC. The service name is what is called from the command line when starting or
stopping services, net start W3SVC and for our own service it would be net start MyService.
You should also make sure the following properties are set to your requirements:
ď‚· AllowPause and AllowStop should be set to true unless otherwise required
ď‚· Interactive should be set to false unless you require to communicate with the Desktop such as via the
ShowMessage command
ď‚· StartType defines at which point during system initialisation should the process start, this should be
set to stAuto if you want it to start at during the system startup or stManual which will allow users
and applications to start it when required
5. Delphi Howto: System Services
3 | P a g e
SERVICE EVENTS
Services come with a set of events that can be used to initialise variables, spawn worker threads as well as
initiating clean up code when a service terminates.
The following is a list of important service events and there meanings:
Event Description
AfterInstall (published) Occurs immediately after the service is registered with the Windows Service Control
manager.
AfterUninstall (published) Occurs immediately after the service is removed from the Service Control manager's
database.
BeforeInstall (published) Occurs before the service is first registered with the Windows Service Control
manager.
BeforeUninstall
(published)
Occurs immediately before the service is removed from the Service Control
manager's database.
OnContinue (published) Occurs when the Service Control manager resumes the service after it has been
paused.
OnExecute (published) Occurs when the thread associated with the service starts up.
OnPause (published) Occurs when the Service Control manager pauses the service temporarily.
OnShutdown (published) Occurs when the system running the service application is about to shut down.
OnStart (published) OnStartup occurs when the service first starts up, before the OnExecute event.
OnStop (published) Occurs when the Service Control manager stops the service.
Table 1: Service events
6. Delphi Howto: System Services
4 | P a g e
KEEPING IT ALIVE
Services, like threads, require a loop in order to stay alive otherwise once it reaches the end of its first run of
the OnExecute method, it will return and the service will exit. To add a method for the OnExecute method
simply double click on the OnExecute event in the design view of the Borland IDE and it will automatically
generate the required method. The following demonstrates a loop that will keep the service alive:
procedure TMyService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
ServiceThread.ProcessRequests(True); // wait for termination
end;
end;
Example 2: Keep alive loop
What the ServiceThread.ProcessRequests(True) does is to keep the thread alive instead of
terminating once it reaches the end of the method. The functionality of the service can come from worker
threads initiated before the loop or from TCP, HTTP or Socket components added in the design view.
7. Delphi Howto: System Services
5 | P a g e
PASSING EVENT SIGNALS TO THREADS
One thing to remember is that if you utilise the Start, Stop, Pause and Continue events and you have worker
threads, you should pass these calls on to them as there is no point pausing a service only for a worker thread
to ignore the request. The following example explains how this would be done:
procedure TMyService.ServiceStart(Sender: TService; var Started: Boolean);
begin
WorkerThread := TWorkerThread.Create(False); // initialise thread
Started := True;
end;
procedure TMyService.ServiceContinue(Sender: TService; var Continued:
Boolean);
begin
WorkerThread.Resume;
Continued := True;
end;
procedure TMyService.ServicePause(Sender: TService; var Paused: Boolean);
begin
WorkerThread.Suspend;
Paused := True;
end;
procedure TMyService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
WorkerThread.Terminate;
Stopped := True;
end;
Example 3: Passing state calls to worker threads
8. Delphi Howto: System Services
6 | P a g e
INSTALLING / UNINSTALLING YOUR SERVICE
Services come with the necessary code to install and uninstall themselves through the use of switches on the
command line or through the Run box located in the start menu. To register a service on a system open a new
Run box, locate your service executable and add the /install switch.
Example 4: Installing your service
Depending on what you specified as the StartType the service will either start during the boot process of the
machine or it will be started manually by users or other applications. To uninstall the service repeat the
process above except instead of the /install switch use /uninstall instead.
Example 5: Service uninstall success
9. Delphi Howto: System Services
7 | P a g e
FULL EXAMPLE
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr,
Dialogs, MyWorkerThread;
{ MyWorkerThread will be a unit that contains TWorkerThread }
type
TMyService = class(TService)
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;var
MyService: TMyService;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
MyService.Controller(CtrlCode);
end;
function TMyService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TMyService.ServiceStart(Sender: TService; var Started: Boolean);
begin
WorkerThread := TWorkerThread.Create(False); // initialise thread
Started := True;
end;
10. Delphi Howto: System Services
8 | P a g e
procedure TMyService.ServiceContinue(Sender: TService; var Continued:
Boolean);
begin
WorkerThread.Resume;
Continued := True;
end;
procedure TMyService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
ServiceThread.ProcessRequests(True); // wait for termination
end;
end;
procedure TMyService.ServicePause(Sender: TService; var Paused: Boolean);
begin
WorkerThread.Suspend;
Paused := True;
end;
procedure TMyService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
WorkerThread.Terminate;
Stopped := True;
end;
end.
Example 6: Full example code
11. Delphi Howto: System Services
9 | P a g e
USEFUL LINKS
Creating a Windows Service in Delphi – http://www.devarticles.com/c/a/Delphi-Kylix/Creating-a-Windows-
Service-in-Delphi/