Windows服务无法启动 [英] Windows service does not start up

查看:80
本文介绍了Windows服务无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#中创建了Windows服务,用于查找特定目录.每当创建一个新文件为PowerPoint文件时,它将其转换为视频文件.我对其进行了测试,该系统具有Windows Server 2003.在另一个系统上启动服务 该操作系统具有相同的操作系统(Windows 2003 Server).出现以下错误:Windows无法启动服务错误代码:1053).

在on start和stop方法中,我有以下代码:

 

受保护的 覆盖 无效 OnStart( [] args){

 

//创建辅助线程;这将在我们启动它时调用WorkerFunction.

 

//由于我们使用单独的工作线程,主要服务

 

//线程将快速返回,告诉Windows该服务已启动

 

ThreadStart startThread = ThreadStart (PeriodicProcess);

workerThread =

线程 (startThread);

 

//设置标志以指示工作线程为活动的

serviceStarted =

;

 

//启动线程

workerThread.Start();

}

 

私有 无效 PeriodicProcess(){

 

//开始无限循环;仅当"serviceStarted"

时,循环才会中止

 

//flag = false

 

同时 (serviceStarted){

 

//做某事

 

//为简单起见,此处省略了异常处理

 

字符串 路径= 使用率 .GetSetting(

 

如果 ( .IsDirectoryPresent(path, false )){

FSWatcher.Path =路径;

FSWatcher.Filter =

"*.*" ;

}

 

//yield

 

如果 (serviceStarted){

 

线程 .Sleep( TimeSpan (0,0,30));

}

}

 

//结束线程的时间

 

线程 .CurrentThread.Abort();

}

 

无效 OnStop()

{

 

//标记以告知工作进程停止

serviceStarted =

false ;

 

//给它一点时间来完成任何待处理的工作

workerThread.Join(

TimeSpan (0,1,0));

}

有人可以帮我吗!

解决方案

可能是您想要获取融合日志并检查所有依赖项是否到位.


I have created windows service in c# which looks for particular directory.Whenever a new file is powerpoint file is created it tranforms it to video file.I tested it a sytem which has windows server 2003.But I could not start the service on another system whach has same OS system(Windows 2003 server).I get the following error: Windows could not start the service error code :1053).

I have following code in the on start and on stop methods :

 

protected override void OnStart(string[] args) {

 

// Create worker thread; this will invoke the WorkerFunction when we start it.

 

// Since we use a separate worker thread, the main service

 

// thread will return quickly, telling Windows that service has started

 

ThreadStart startThread = new ThreadStart(PeriodicProcess);

workerThread =

new Thread(startThread);

 

// set flag to indicate worker thread is active

serviceStarted =

true;

 

// start the thread

workerThread.Start();

}

 

private void PeriodicProcess() {

 

// start an endless loop; loop will abort only when "serviceStarted"

 

// flag = false

 

while (serviceStarted) {

 

// do something

 

// exception handling omitted here for simplicity

 

string path = Util.GetSetting("PATHTOWATCH");

 

if (Util.IsDirectoryPresent(path, false)) {

FSWatcher.Path = path;

FSWatcher.Filter =

"*.*";

}

 

// yield

 

if (serviceStarted) {

 

Thread.Sleep(new TimeSpan(0, 0, 30));

}

}

 

// time to end the thread

 

Thread.CurrentThread.Abort();

}

protected

 

override void OnStop()

{

 

// flag to tell the worker process to stop

serviceStarted =

false;

 

// give it a little time to finish any pending work

workerThread.Join(

new TimeSpan(0, 1, 0));

}

Could somebody help me !

解决方案

May be you want to take a fusion log and check if all the dependencies are in place.


这篇关于Windows服务无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆