It was written in Windows Service (windows service program) in the .NET Framework and .NET Core Framework

  Introduction, why are Windows Service written in two frames, because of the recent block chain in doing this, using the NEO (small ants block chain) related technologies, NEO using the .net core 2.1, business the need to write two programs, a synchronous data to a local, a chain maintain access to the data. Before the console has been used, but easy to misuse after deployment, shut down like (in fact, a thought began to respect), it is necessary to change the windows service. To use .NET Framework and .NET Core have tried it.

IDE: vs2017

Windows Service written under the .NET Framework

1. Create a project

2, will be renamed the Service1 own name BlockSyncService, and write your own programs

 

3, attributes set WindowsService

Navigate to BlockSyncService page and look at the code, in OnSatrt () and OnStop () method writes the corresponding service start and stop code.

4, back BlockSyncService design page, right blank space and select "Add Installer"

5, right serviceProcessInstaller1 select properties provided Account LocalSystem (account) is;

     Right serviceinstaller1 select properties, set Description (description of the deployment of services), ServiceName (name of the deployment services), StartType (the service is started (since the launch -Automatic, manually start -Manual, prohibit start -Disabled, etc.))

     After setting rebuild the solution.

6, deployment services

Run as Administrator cmd, enter the command sc create service names binPath = "path to the program exe file" is used to create a service

Note: the emergence of "[SC] OpenSCManager Failed 5: Access Denied" error, use an Administrator, open a command prompt (cmd)

If the startup mode is not set, and then may enter commands sc config BlockSyncService start = "AUTO" arranged for starting services (AUTO- from the start)

After successful configuration, type net start BlockSyncService start the service.

 

 7, service commissioning

WindowsService not directly debugging, it has been launched only in the case of services, by attaching to process, for debugging purposes. As shown below

Check the "All Users"

Choose their own service process, and additional

Note: Attached is unable to process debugging OnStart () method, under normal circumstances can OnStart () code into OnStop () is executed and debugged. Debugging is relatively trouble.

 

 

Finally, win + r swevices.msc and enter into the service management interface, right trigger to stop debugging.

 

.NET Core preparing its Windows Service

1, create a .net core console project

2, add WindowsService items

 

Once created, an error message appears. This is because no namespace "System.ServiceProcess.ServiceController", need nuget installation.

3, to write their own program, SBS-RPC-Service.cs provided in the OnStart () and the OnStop (), and finally set the Program.cs, re-tagging.

 

 

Debugging and deployment steps with the .NET Framework steps are basically the same, but the .net core need to be released, binPath = "path release .exe program", the other is no different when creating a service, I will not repeat here say .

 Incidentally attached at the official hosting ASP.NET Core Services in Windows documents: https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1

 
Category:  .Net
 
0
0

 

 
 
 

  Introduction, why are Windows Service written in two frames, because of the recent block chain in doing this, using the NEO (small ants block chain) related technologies, NEO using the .net core 2.1, business the need to write two programs, a synchronous data to a local, a chain maintain access to the data. Before the console has been used, but easy to misuse after deployment, shut down like (in fact, a thought began to respect), it is necessary to change the windows service. To use .NET Framework and .NET Core have tried it.

IDE: vs2017

Windows Service written under the .NET Framework

1. Create a project

2, will be renamed the Service1 own name BlockSyncService, and write your own programs

 

3, attributes set WindowsService

Navigate to BlockSyncService page and look at the code, in OnSatrt () and OnStop () method writes the corresponding service start and stop code.

4, back BlockSyncService design page, right blank space and select "Add Installer"

5, right serviceProcessInstaller1 select properties provided Account LocalSystem (account) is;

     Right serviceinstaller1 select properties, set Description (description of the deployment of services), ServiceName (name of the deployment services), StartType (the service is started (since the launch -Automatic, manually start -Manual, prohibit start -Disabled, etc.))

     After setting rebuild the solution.

6, deployment services

Run as Administrator cmd, enter the command sc create service names binPath = "path to the program exe file" is used to create a service

Note: the emergence of "[SC] OpenSCManager Failed 5: Access Denied" error, use an Administrator, open a command prompt (cmd)

If the startup mode is not set, and then may enter commands sc config BlockSyncService start = "AUTO" arranged for starting services (AUTO- from the start)

After successful configuration, type net start BlockSyncService start the service.

 

 7, service commissioning

WindowsService not directly debugging, it has been launched only in the case of services, by attaching to process, for debugging purposes. As shown below

Check the "All Users"

Choose their own service process, and additional

Note: Attached is unable to process debugging OnStart () method, under normal circumstances can OnStart () code into OnStop () is executed and debugged. Debugging is relatively trouble.

 

 

Finally, win + r swevices.msc and enter into the service management interface, right trigger to stop debugging.

 

.NET Core preparing its Windows Service

1, create a .net core console project

2, add WindowsService items

 

Once created, an error message appears. This is because no namespace "System.ServiceProcess.ServiceController", need nuget installation.

3, to write their own program, SBS-RPC-Service.cs provided in the OnStart () and the OnStop (), and finally set the Program.cs, re-tagging.

 

 

Debugging and deployment steps with the .NET Framework steps are basically the same, but the .net core need to be released, binPath = "path release .exe program", the other is no different when creating a service, I will not repeat here say .

 Incidentally attached at the official hosting ASP.NET Core Services in Windows documents: https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1

Guess you like

Origin www.cnblogs.com/webenh/p/11578582.html