启动Windows服务后出现错误1053

时间:2018-10-18 13:23:01

标签: c# service

我创建了一个与InstallUtil一起安装的Windows服务,并开始使用Services应用程序……我最终收到此错误

enter image description here

enter image description here

但是从此“日志”屏幕告诉我该服务已启动(在我的服务中,这是我将其连接到数据库后写的一条消息) enter image description here

但是在服务应用程序上,状态始终为“正在启动”,我无法停止它,因为服务显示“我无法接收消息”

这是Program.cs类

static void Main(string[] args)
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new InterCompanyService()
            };
#if DEBUG
            if (Environment.UserInteractive)
            {
                const BindingFlags bindingFlags =
                    BindingFlags.Instance | BindingFlags.NonPublic;

                foreach (var serviceBase in ServicesToRun)
                {
                    var serviceType = serviceBase.GetType();
                    var methodInfo = serviceType.GetMethod("OnStart", bindingFlags);

                    new Thread(service => methodInfo.Invoke(service, new object[] { args })).Start(serviceBase);
                }

                return;
            }
#endif
            ServiceBase.Run(ServicesToRun);
        }

班级服务

public InterCompanyService()
        {
            InitializeComponent();


            EventSourceCreationData escd = new EventSourceCreationData(eventLog.Source, eventLog.Log);

            if (!EventLog.SourceExists(eventLog.Source))
            {
                EventLog.CreateEventSource(escd);
            }
        }

在OnStart中,我尝试通过EntityFramework连接到我的数据库

0 个答案:

没有答案