保持C#应用程序运行

保持C#应用程序运行

本文介绍了保持C#应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个使用FileSystemWatcher的,并在后台运行Windows服务。

I'm building a Windows Service that uses FileSystemWatcher, and runs in the background.

我不希望继续卸载,我想调试每次安装服务,所以想动它变成一个服务之前做了我的大部分发展在一个正常的程序。但我很新的这一点,当我运行它,它只是通过大宗并退出运行。

I don't want to keep on uninstalling and installing the service every time I want to debug, so would like to do most of my development in a normal program before moving it into a service. But I'm quite new to this, and when I run it, it just runs through the block and exits.

什么是保持程序的运行状态的好办法?

What would be a good way to keep the program running?

推荐答案

http://einaregilsson.com/run-windows-service-as-a-console-program/

我用这个之前,根据是否调试我的服务作为控制台应用程序及其在交互式用户环境中运行。

I've used this before to debug my service as a Console application based on whether its running in an interactive user environment.

public partial class DemoService : ServiceBase
{
    static void Main(string[] args)
    {
        DemoService service = new DemoService();

        if (Environment.UserInteractive)
        {
            service.OnStart(args);
            Console.WriteLine("Press any key to stop program");
            Console.Read();
            service.OnStop();
        }
        else
        {
            ServiceBase.Run(service);
        }
    }

这篇关于保持C#应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:38