C # precautions for installing the intermediate-Windows Service Program,

Source: Internet
Author: User

C # precautions for installing the intermediate-Windows Service Program,

I. Preface

In addition to rewriting some recognition algorithms this week, I continued to write my Socket service. The server-side Socket Service runs in the form of a Windows Service.

After I write Windows Service, errors always occur when I start the Service. Here I will summarize how to install, start, and troubleshoot.

 

Ii. Text

Let's talk about the installation of Windows Service, which is the most basic. After writing a Windows Service, you usually need to execute a script in the same directory as the Windows Service application:

% SystemRoot % \ Microsoft. NET \ Framework \ v4.0.30319 \ installutil.exe UpdaterService.exe // UpdaterService is the Service application. Net Start SocketService // SocketService is the Service name SC config SocketService start = autopause

 

When the script execution fails to start the service (1053-the service did not respond to the startup or control request in time), it indicates that your application is faulty.

First, check whether the Windows Service Application dll is complete and whether there are any omissions.

Then, if the compilation is successful, check whether your Service code is running in a thread:

using System;using System.IO;using System.ServiceProcess;using System.Threading;using System.Threading.Tasks;namespace UpdaterService{    public partial class SocketService : ServiceBase    {        Thread threadforwork = null;        public SocketService()        {            InitializeComponent();        }        protected override void OnStart(string[] args)        {            if (threadforwork == null)            {                threadforwork = new Thread(p =>                {                    try                    {                        //Your Service                     }                    catch (Exception ex)                    {                        //Log Here                    }                });                threadforwork.IsBackground = true;                threadforwork.Start();            }              }        protected override void OnStop()        {            if (threadforwork?.ThreadState == ThreadState.Running)            {                threadforwork.Abort();            }        }    }}

If you need to uninstall Windows Service after the installation is complete, execute another script. the uninstallation script and Windows Service application are also in the same directory:

net stop SocketService%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u UpdaterService.exepause

If you want to delete the directory where the Windows Service application is located, You can normally delete it completely.

But sometimes it cannot be completely deleted, prompting you that the current program is in use and cannot be deleted. This usually happens when the service is successfully installed. When the service fails to be started, You Cannot uninstall it completely.

You need to run the command line to delete the clean:

SC queryex ServiceName // The PIDtaskkill/PID ServicePID/f of the service is displayed.

After the command line shows that the PID has been successfully deleted, you can delete the directory where the application is located.

 

Iii. Conclusion

This week, I got down in my second exam. I practiced well and got into the test room. It was amazing that I had to roll my ass twice when I got into the test room! The strange thing is that, when I got down, my mood was exceptionally good and I felt like the whole person was suddenly better. The first few weeks of sleep are not good, and there is always insomnia. After hanging up, I slept very well every day, and my appetite for eating at the company was much better. Maybe this is my destiny. The online Upgrade Program is almost finished. You can perform stress testing. Next time, I will be able to take the second test under the blessing of the gods! Amen, Amitabha, and arakaba!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.