SlideShare a Scribd company logo
WIN SERVICE BEST PRACTICE
Yu Guan | Microsoft MVP
Meet Yu Guan | @askguanyu
twitter.com/askguanyu
linkedin.com/in/yuguan
askguanyu.wordpress.com
devlib.codeplex.com
Microsoft MVP
Speaker, Blogger, Hacker, Coder, Maker, Gamer
Azure, IoT, Cross-platform Apps, GIS, Services
WINDOWS SERVICE GUIDELINE
 Implementation Segmentation
 Installation
 Debugging
Implementation Segmentation
  You should separate business logic into individual projects.
INSTALLATION
 Need installer component and mark the class attribute as [RunInstaller(true)]
 You can use command line to install/uninstall windows service.
 You can use .net feature to install/uninstall windows service.
Debugging
 Run in console
 Attach process
 Debugger.Launch() and Debugger.Break()
 Thread.Sleep(xxx)
DevLib.ServiceProcess
 NuGet: https://www.nuget.org/packages/DevLib.ServiceProcess/
 Source code:
https://devlib.codeplex.com/SourceControl/latest#Main/Source/DevLib.ServicePr
ocess/
 Easy to port
 Solve pain points
DEMO
APPENDIX
Wording Intent
 Do... This standard or practice should be followed in all cases. If you think that your specific application
is exempt, it probably isn't.
 Do Not... This standard or practice should never be applied.
 You should... This standard or practice should be followed in most cases.
 You should not... This standard or practice should not be followed, unless there's reasonable justification.
 You can… This standard or practice can be followed if you want to; it's not necessarily good or bad. There
are probably implications to following the practice (dependencies, or constraints) that should be
considered before adopting it.
THANK YOU!

More Related Content

What's hot

Why Salesforce Commerce Cloud?
Why Salesforce Commerce Cloud?Why Salesforce Commerce Cloud?
Why Salesforce Commerce Cloud?
Docmation
 
Cultura DevOps e integração entre infra e devel
Cultura DevOps e integração entre infra e develCultura DevOps e integração entre infra e devel
Cultura DevOps e integração entre infra e devel
Jose Augusto Carvalho
 
Google cloud platform
Google cloud platformGoogle cloud platform
Google cloud platform
Ankit Malviya
 
AWS Business Essentials
AWS Business EssentialsAWS Business Essentials
AWS Business Essentials
Amazon Web Services
 
Google Cloud Platform Tutorial | GCP Fundamentals | Edureka
Google Cloud Platform Tutorial | GCP Fundamentals | EdurekaGoogle Cloud Platform Tutorial | GCP Fundamentals | Edureka
Google Cloud Platform Tutorial | GCP Fundamentals | Edureka
Edureka!
 
Azure 10 major services
Azure 10 major servicesAzure 10 major services
Azure 10 major services
Arnab Chakraborty,PMP
 
Legacy application modernization with microsoft azure
Legacy application modernization with microsoft azureLegacy application modernization with microsoft azure
Legacy application modernization with microsoft azure
OptiSol Business Solutions
 
Cloud computing
Cloud computingCloud computing
Cloud computing
ACCESS Health Digital
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud Computing
Sayed Chhattan Shah
 
Understanding cloud with Google Cloud Platform
Understanding cloud with Google Cloud PlatformUnderstanding cloud with Google Cloud Platform
Understanding cloud with Google Cloud Platform
Dr. Ketan Parmar
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp VaultAWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp Vault
Grzegorz Adamowicz
 
Introduction to GCP presentation
Introduction to GCP presentationIntroduction to GCP presentation
Introduction to GCP presentation
Mohit Kachhwani
 
Cloud 101: The Basics of Cloud Computing
Cloud 101: The Basics of Cloud ComputingCloud 101: The Basics of Cloud Computing
Cloud 101: The Basics of Cloud Computing
Hostway|HOSTING
 
Introduction to AWS Cloud Computing
Introduction to AWS Cloud ComputingIntroduction to AWS Cloud Computing
Introduction to AWS Cloud Computing
Amazon Web Services
 
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
Edureka!
 
Microservice Architecture 101
Microservice Architecture 101Microservice Architecture 101
Microservice Architecture 101
Kochih Wu
 
Dynatrace Cloud-Native Workshop Slides
Dynatrace Cloud-Native Workshop SlidesDynatrace Cloud-Native Workshop Slides
Dynatrace Cloud-Native Workshop Slides
VMware Tanzu
 
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
Erwin de Kreuk
 
Flow in Salesforce
Flow in SalesforceFlow in Salesforce
Flow in Salesforce
vikas singh
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
Amazon Web Services
 

What's hot (20)

Why Salesforce Commerce Cloud?
Why Salesforce Commerce Cloud?Why Salesforce Commerce Cloud?
Why Salesforce Commerce Cloud?
 
Cultura DevOps e integração entre infra e devel
Cultura DevOps e integração entre infra e develCultura DevOps e integração entre infra e devel
Cultura DevOps e integração entre infra e devel
 
Google cloud platform
Google cloud platformGoogle cloud platform
Google cloud platform
 
AWS Business Essentials
AWS Business EssentialsAWS Business Essentials
AWS Business Essentials
 
Google Cloud Platform Tutorial | GCP Fundamentals | Edureka
Google Cloud Platform Tutorial | GCP Fundamentals | EdurekaGoogle Cloud Platform Tutorial | GCP Fundamentals | Edureka
Google Cloud Platform Tutorial | GCP Fundamentals | Edureka
 
Azure 10 major services
Azure 10 major servicesAzure 10 major services
Azure 10 major services
 
Legacy application modernization with microsoft azure
Legacy application modernization with microsoft azureLegacy application modernization with microsoft azure
Legacy application modernization with microsoft azure
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud Computing
 
Understanding cloud with Google Cloud Platform
Understanding cloud with Google Cloud PlatformUnderstanding cloud with Google Cloud Platform
Understanding cloud with Google Cloud Platform
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp VaultAWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp Vault
 
Introduction to GCP presentation
Introduction to GCP presentationIntroduction to GCP presentation
Introduction to GCP presentation
 
Cloud 101: The Basics of Cloud Computing
Cloud 101: The Basics of Cloud ComputingCloud 101: The Basics of Cloud Computing
Cloud 101: The Basics of Cloud Computing
 
Introduction to AWS Cloud Computing
Introduction to AWS Cloud ComputingIntroduction to AWS Cloud Computing
Introduction to AWS Cloud Computing
 
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
Cloud Computing Service Models | IaaS PaaS SaaS Explained | Cloud Masters Pro...
 
Microservice Architecture 101
Microservice Architecture 101Microservice Architecture 101
Microservice Architecture 101
 
Dynatrace Cloud-Native Workshop Slides
Dynatrace Cloud-Native Workshop SlidesDynatrace Cloud-Native Workshop Slides
Dynatrace Cloud-Native Workshop Slides
 
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
Azure Key Vault, Azure Dev Ops and Azure Synapse - how these services work pe...
 
Flow in Salesforce
Flow in SalesforceFlow in Salesforce
Flow in Salesforce
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 

Similar to Windows service best practice

System development using visual studio
System development using visual studioSystem development using visual studio
System development using visual studio
jeff23_athisbest
 
ZCM update VAI Brainforce
ZCM update VAI BrainforceZCM update VAI Brainforce
ZCM update VAI Brainforce
Roel van Bueren
 
Web Deploy for releasing web applications
Web Deploy for releasing web applicationsWeb Deploy for releasing web applications
Web Deploy for releasing web applications
Techorama
 
VS Code and Modern Development Environment Preview
VS Code and Modern Development Environment PreviewVS Code and Modern Development Environment Preview
VS Code and Modern Development Environment Preview
Roberto Stefanetti
 
Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010
joycsc
 
Automated Build using teamcity
Automated Build using teamcityAutomated Build using teamcity
Automated Build using teamcity
Md Jawed
 
Extending the Enterprise with MEF
Extending the Enterprise with MEFExtending the Enterprise with MEF
Extending the Enterprise with MEF
Brian Ritchie
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
Simona Cotin
 
Troubleshooting the Windows Installer
Troubleshooting the Windows Installer Troubleshooting the Windows Installer
Troubleshooting the Windows Installer
AppDetails
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
Mikkel Flindt Heisterberg
 
Vs2005p
Vs2005pVs2005p
Vs2005p
cm_chitta
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architecture
Synapseindiappsdevelopment
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
Oliver N
 
De Zero a Produção - João Jesus
De Zero a Produção - João JesusDe Zero a Produção - João Jesus
De Zero a Produção - João Jesus
Comunidade NetPonto
 
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
VISEO
 
Ordina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better togetherOrdina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better together
Ordina Belgium
 
Dont fear software patching for operational technology
Dont fear software patching for operational technologyDont fear software patching for operational technology
Dont fear software patching for operational technology
Jo Ee Liew
 
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the CloudWSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
WSO2
 
Revisiting Silent: Installs Are they still useful?
Revisiting Silent: Installs Are they still useful?Revisiting Silent: Installs Are they still useful?
Revisiting Silent: Installs Are they still useful?
Revelation Technologies
 
Introducing Visual Studio LightSwitch
Introducing Visual Studio LightSwitchIntroducing Visual Studio LightSwitch
Introducing Visual Studio LightSwitch
Nuchit Atjanawat
 

Similar to Windows service best practice (20)

System development using visual studio
System development using visual studioSystem development using visual studio
System development using visual studio
 
ZCM update VAI Brainforce
ZCM update VAI BrainforceZCM update VAI Brainforce
ZCM update VAI Brainforce
 
Web Deploy for releasing web applications
Web Deploy for releasing web applicationsWeb Deploy for releasing web applications
Web Deploy for releasing web applications
 
VS Code and Modern Development Environment Preview
VS Code and Modern Development Environment PreviewVS Code and Modern Development Environment Preview
VS Code and Modern Development Environment Preview
 
Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010
 
Automated Build using teamcity
Automated Build using teamcityAutomated Build using teamcity
Automated Build using teamcity
 
Extending the Enterprise with MEF
Extending the Enterprise with MEFExtending the Enterprise with MEF
Extending the Enterprise with MEF
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
 
Troubleshooting the Windows Installer
Troubleshooting the Windows Installer Troubleshooting the Windows Installer
Troubleshooting the Windows Installer
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
Vs2005p
Vs2005pVs2005p
Vs2005p
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architecture
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
 
De Zero a Produção - João Jesus
De Zero a Produção - João JesusDe Zero a Produção - João Jesus
De Zero a Produção - João Jesus
 
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
What’s new in Microsoft ALM 2013, hosted in Windows Azure, VISUAL STUDIO ONLI...
 
Ordina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better togetherOrdina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - TFS and JAVA, better together
 
Dont fear software patching for operational technology
Dont fear software patching for operational technologyDont fear software patching for operational technology
Dont fear software patching for operational technology
 
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the CloudWSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
WSO2Con US 2013 - Keynote: Developing Enterprise Apps In the Cloud
 
Revisiting Silent: Installs Are they still useful?
Revisiting Silent: Installs Are they still useful?Revisiting Silent: Installs Are they still useful?
Revisiting Silent: Installs Are they still useful?
 
Introducing Visual Studio LightSwitch
Introducing Visual Studio LightSwitchIntroducing Visual Studio LightSwitch
Introducing Visual Studio LightSwitch
 

More from Yu GUAN

Canada Chinese Microsoft Tech Club Event 1
Canada Chinese Microsoft Tech Club Event 1Canada Chinese Microsoft Tech Club Event 1
Canada Chinese Microsoft Tech Club Event 1
Yu GUAN
 
Asp netmvc e03
Asp netmvc e03Asp netmvc e03
Asp netmvc e03
Yu GUAN
 
You can git
You can gitYou can git
You can git
Yu GUAN
 
A Journey to Azure
A Journey to AzureA Journey to Azure
A Journey to Azure
Yu GUAN
 
Dream career dot NET
Dream career dot NETDream career dot NET
Dream career dot NET
Yu GUAN
 
NuGet package CI and CD
NuGet package CI and CDNuGet package CI and CD
NuGet package CI and CD
Yu GUAN
 
Hosting your own NuGet private repository
Hosting your own NuGet private repositoryHosting your own NuGet private repository
Hosting your own NuGet private repository
Yu GUAN
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
Yu GUAN
 
Unleash the power of code reuse - creating plugins for Xamarin
Unleash the power of code reuse - creating plugins for XamarinUnleash the power of code reuse - creating plugins for Xamarin
Unleash the power of code reuse - creating plugins for Xamarin
Yu GUAN
 
A Journey To Microsoft Azure E00 Azure 101
A Journey To Microsoft Azure E00 Azure 101A Journey To Microsoft Azure E00 Azure 101
A Journey To Microsoft Azure E00 Azure 101
Yu GUAN
 
Welcome to power point
Welcome to power pointWelcome to power point
Welcome to power point
Yu GUAN
 

More from Yu GUAN (11)

Canada Chinese Microsoft Tech Club Event 1
Canada Chinese Microsoft Tech Club Event 1Canada Chinese Microsoft Tech Club Event 1
Canada Chinese Microsoft Tech Club Event 1
 
Asp netmvc e03
Asp netmvc e03Asp netmvc e03
Asp netmvc e03
 
You can git
You can gitYou can git
You can git
 
A Journey to Azure
A Journey to AzureA Journey to Azure
A Journey to Azure
 
Dream career dot NET
Dream career dot NETDream career dot NET
Dream career dot NET
 
NuGet package CI and CD
NuGet package CI and CDNuGet package CI and CD
NuGet package CI and CD
 
Hosting your own NuGet private repository
Hosting your own NuGet private repositoryHosting your own NuGet private repository
Hosting your own NuGet private repository
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
 
Unleash the power of code reuse - creating plugins for Xamarin
Unleash the power of code reuse - creating plugins for XamarinUnleash the power of code reuse - creating plugins for Xamarin
Unleash the power of code reuse - creating plugins for Xamarin
 
A Journey To Microsoft Azure E00 Azure 101
A Journey To Microsoft Azure E00 Azure 101A Journey To Microsoft Azure E00 Azure 101
A Journey To Microsoft Azure E00 Azure 101
 
Welcome to power point
Welcome to power pointWelcome to power point
Welcome to power point
 

Recently uploaded

All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
anfaltahir1010
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 

Recently uploaded (20)

All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 

Windows service best practice

  • 1. WIN SERVICE BEST PRACTICE Yu Guan | Microsoft MVP
  • 2. Meet Yu Guan | @askguanyu twitter.com/askguanyu linkedin.com/in/yuguan askguanyu.wordpress.com devlib.codeplex.com Microsoft MVP Speaker, Blogger, Hacker, Coder, Maker, Gamer Azure, IoT, Cross-platform Apps, GIS, Services
  • 3. WINDOWS SERVICE GUIDELINE  Implementation Segmentation  Installation  Debugging
  • 4. Implementation Segmentation   You should separate business logic into individual projects.
  • 5. INSTALLATION  Need installer component and mark the class attribute as [RunInstaller(true)]  You can use command line to install/uninstall windows service.  You can use .net feature to install/uninstall windows service.
  • 6. Debugging  Run in console  Attach process  Debugger.Launch() and Debugger.Break()  Thread.Sleep(xxx)
  • 7. DevLib.ServiceProcess  NuGet: https://www.nuget.org/packages/DevLib.ServiceProcess/  Source code: https://devlib.codeplex.com/SourceControl/latest#Main/Source/DevLib.ServicePr ocess/  Easy to port  Solve pain points
  • 9. APPENDIX Wording Intent  Do... This standard or practice should be followed in all cases. If you think that your specific application is exempt, it probably isn't.  Do Not... This standard or practice should never be applied.  You should... This standard or practice should be followed in most cases.  You should not... This standard or practice should not be followed, unless there's reasonable justification.  You can… This standard or practice can be followed if you want to; it's not necessarily good or bad. There are probably implications to following the practice (dependencies, or constraints) that should be considered before adopting it.

Editor's Notes

  1. How to: Install and Uninstall Services .NET Framework (current version) Other Versions Visual Studio 2010 .NET Framework 3.5 .NET Framework 2.0  If you’re developing a Windows Service by using the .NET Framework, you can quickly install your service application by using a command-line utility called InstallUtil.exe. If you’re a developer who wants to release a Windows Service that users can install and uninstall you should use InstallShield. See 121be21b-b916-43e2-8f10-8b080516d2a0. Warning If you want to uninstall a service from your computer, don’t follow the steps in this article. Instead, find out which program or software package installed the service, and then choose Add/Remove Programs in Control Panel to uninstall that program. Note that many services are integral parts of Windows; if you remove them, you might cause system instability. In order to use the steps in this article, you first need to add a service installer to your Windows Service. See Walkthrough: Creating a Windows Service Application in the Component Designer. Windows Service projects cannot be run directly from the Visual Studio development environment by pressing F5. This is because the service in the project must be installed before you can run the project. Tip You can launch Server Explorer and verify that your service has been installed or uninstalled. For more information, see How to: Access and Initialize Server Explorer/Database Explorer. To install your service manually On the Windows Start menu or Start screen, choose Visual Studio , Visual Studio Tools, Developer Command Prompt. A Visual Studio command prompt appears. Access the directory where your project's compiled executable file is located. Run InstallUtil.exe from the command prompt with your project's executable as a parameter: Copy installutil <yourproject>.exe If you’re using the Visual Studio command prompt, InstallUtil.exe should be on the system path. If not, you can add it to the path, or use the fully qualified path to invoke it. This tool is installed with the .NET Framework, and its path is %WINDIR%\Microsoft.NET\Framework[64]\<framework_version>. For example, for the 32-bit version of the .NET Framework 4 or 4.5.*, if your Windows installation directory is C:\Windows, the path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe. For the 64-bit version of the .NET Framework 4 or 4.5.*, the default path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe. To uninstall your service manually On the Windows Start menu or Start screen, choose Visual Studio, Visual Studio Tools, Developer Command Prompt. A Visual Studio command prompt appears. Run InstallUtil.exe from the command prompt with your project's output as a parameter: Copy installutil /u <yourproject>.exe Sometimes, after the executable for a service is deleted, the service might still be present in the registry. In that case, use the command sc delete to remove the entry for the service from the registry.
  2. How to: Debug Windows Service Applications .NET Framework (current version) Other Versions Visual Studio 2010 .NET Framework 3.5 .NET Framework 2.0  A service must be run from within the context of the Services Control Manager rather than from within Visual Studio. For this reason, debugging a service is not as straightforward as debugging other Visual Studio application types. To debug a service, you must start the service and then attach a debugger to the process in which it is running. You can then debug your application by using all of the standard debugging functionality of Visual Studio. Caution You should not attach to a process unless you know what the process is and understand the consequences of attaching to and possibly killing that process. For example, if you attach to the WinLogon process and then stop debugging, the system will halt because it can’t operate without WinLogon. You can attach the debugger only to a running service. The attachment process interrupts the current functioning of your service; it doesn’t actually stop or pause the service's processing. That is, if your service is running when you begin debugging, it is still technically in the Started state as you debug it, but its processing has been suspended. After attaching to the process, you can set breakpoints and use these to debug your code. Once you exit the dialog box you use to attach to the process, you are effectively in debug mode. You can use the Services Control Manager to start, stop, pause and continue your service, thus hitting the breakpoints you've set. You can later remove this dummy service after debugging is successful. This article covers debugging a service that's running on the local computer, but you can also debug Windows Services that are running on a remote computer. See Remote Debugging. Note Debugging the OnStart method can be difficult because the Services Control Manager imposes a 30-second limit on all attempts to start a service. For more information, see Troubleshooting: Debugging Windows Services. Warning To get meaningful information for debugging, the Visual Studio debugger needs to find symbol files for the binaries that are being debugged. If you are debugging a service that you built in Visual Studio, the symbol files (.pdb files) are in the same folder as the executable or library, and the debugger loads them automatically. If you are debugging a service that you didn't build, you should first find symbols for the service and make sure they can be found by the debugger. See Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger. If you're debugging a system process or want to have symbols for system calls in your services, you should add the Microsoft Symbol Servers. See Debugging Symbols. To debug a service Build your service in the Debug configuration. Install your service. For more information, see How to: Install and Uninstall Services. Start your service, either from Services Control Manager, Server Explorer, or from code. For more information, see How to: Start Services. Start Visual Studio with administrative credentials so you can attach to system processes. (Optional) On the Visual Studio menu bar, choose Tools, Options. In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button. On the menu bar, choose Attach to Process from the Debug or Tools menu. (Keyboard: Ctrl+Alt+P) The Processes dialog box appears. Select the Show processes from all users check box. In the Available Processes section, choose the process for your service, and then choose Attach. Tip The process will have the same name as the executable file for your service. The Attach to Process dialog box appears. Choose the appropriate options, and then choose OK to close the dialog box. Note You are now in debug mode. Set any breakpoints you want to use in your code. Access the Services Control Manager and manipulate your service, sending stop, pause, and continue commands to hit your breakpoints. For more information about running the Services Control Manager, see How to: Start Services. Also, see Troubleshooting: Debugging Windows Services. Debugging Tips for Windows Services Attaching to the service's process allows you to debug most, but not all, the code for that service. For example, because the service has already been started, you cannot debug the code in the service's OnStart method or the code in the Main method that is used to load the service this way. One way to work around this limitation is to create a temporary second service in your service application that exists only to aid in debugging. You can install both services, and then start this dummy service to load the service process. Once the temporary service has started the process, you can use the Debug menu in Visual Studio to attach to the service process. Try adding calls to the Sleep method to delay action until you’re able to attach to the process. Try changing the program to a regular console application. To do this, rewrite the Main method as follows so it can run both as a Windows Service and as a console application, depending on how it's started. How to: Run a Windows Service as a console application Add a method to your service that runs the OnStart and OnStop methods: Copy internal void TestStartupAndStop(string[] args) { this.OnStart(args); Console.ReadLine(); this.OnStop(); } Rewrite the Main method as follows: Copy static void Main(string[] args) { if (Environment.UserInteractive) { MyNewService service1 = new MyNewService(args); service1.TestStartupAndStop(args); } else { // Put the body of your old Main method here. } In the Application tab of the project's properties, set the Output type to Console Application. Choose Start Debugging (F5). To run the program as a Windows Service again, install it and start it as usual for a Windows Service. It's not necessary to reverse these changes. In some cases, such as when you want to debug an issue that occurs only on system startup, you have to use the Windows debugger. Install Debugging Tools for Windows and see How to debug Windows Services.