我正在开发一个在Windows平台上使用.NET的服务。
它一直有效到昨天…但今天不想开始!!!!看起来很奇怪,我觉得我错过了什么…
我还尝试将源恢复到上一个工作版本,但没有发生其他情况:
网络启动
输出:
服务没有响应控制功能。
什么会导致这个故障?
也许你们大多数人都想了解更多。那么,让我给你看一些代码:
服务代码:
#if DEBUG
class iGeckoService : DebuggableService
#else
class iGeckoService : ServiceBase
#endif
{
static void Main()
{
#if DEBUG
if (Debugger.IsAttached == true) {
DebuggableService[] services = Services;
// Create console
AllocConsole();
// Emulate ServiceBase.Run
foreach (DebuggableService service in services)
service.Start(null);
// Wait for new line
Console.WriteLine("Press ENTER to exit..."); Console.ReadLine();
// Emulate ServiceBase.Run
foreach (DebuggableService service in services)
service.Stop();
} else
ServiceBase.Run(Services);
#else
ServiceBase.Run(Services);
#endif
}
#if DEBUG
static DebuggableService[] Services
{
get {
return (new DebuggableService[] { new iGeckoService() });
}
}
[DllImport("kernel32")]
static extern bool AllocConsole();
#else
static DebuggableService[] Services
{
get {
return (new ServiceBase[] { new iGeckoService() });
}
}
#endif
#endregion
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public iGeckoService()
{
// Base properties
ServiceName = DefaultServiceName;
// Service feature - Power events
}
#endregion
protected override void OnStart(string[] args)
{
try {
...
} catch (Exception e) {
sLog.Error("Unable to initialize the service. Request to stop.", e);
}
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
...
}
}
[RunInstaller(true)]
public class iGeckoDaemonInstaller : Installer
{
/// <summary>
/// Default constructor.
/// </summary>
public iGeckoDaemonInstaller()
{
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = ServiceAccount.LocalSystem;
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = iGeckoService.DefaultServiceName;
si.StartType = ServiceStartMode.Automatic;
Installers.AddRange(new Installer[] {spi, si});
}
}
class DebuggableService : ServiceBase
{
public void Start(string[] args) { OnStart(args); }
}
开始脚本是:
installutil ..\bin\Debug\iGeckoService.exe
net start "Gecko Videowall"
当停止脚本是:
net stop "Gecko Videowall"
installutil /u ..\bin\Debug\iGeckoService.exe
但是,我认为这是一个系统设置,因为应用程序直到最后一天都运行良好。(叹气)
更新
当服务工作时,我使用log4net记录服务活动(我无法将调试程序附加到正在运行的服务…),并且它始终记录。
从现在开始,它永远不会被创建的log4net日志(即使我启用了内部调试选项),即使我在主例程上登录!
另一个更新
似乎从未执行过该应用程序。我减少了所有的程序(主程序、启动程序、启动程序),并且运行了一个空服务。OnStart例程在一个目录上创建一个文件(每个人都可以完全写入),但是当服务启动时,不会创建任何文件。
又一个更新
在Rob的评论的刺激下,我在事件查看器上看到了以下消息:
> Faulting application name: iGeckoService.exe, version: 1.0.0.0, time stamp: 0x4c60de6a
> Faulting module name: ntdll.dll, version: 6.1.7600.16385, time stamp: 0x4a5be02b
> Exception code: 0x80000003
> Fault offset: 0x000000000004f190
> Faulting process id: 0x1258
> Faulting application start time: 0x01cb384a726c7167
> Faulting application path: C:\Users\Luca\Documents\Projects\iGeckoSvn\iGeckoService\bin\Debug\iGeckoService.exe
> Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
> Report Id: b096a237-a43d-11df-afc4-001e8c414537
这无疑是服务关闭的原因…问题不是这样的:“
如何调试它?
“(谢谢Rob,我到现在才想到事件查看器!)
调试它作为控制台应用程序运行,它不会显示任何错误,实际上它似乎与服务环境有关。我唯一想到的可能是某个DLL加载失败,因为现在服务是空的…有什么想法吗?
(谢谢大家跟踪我…我想给你提供披萨和啤酒)
解决了的!
由于安装和安装MS应用程序验证程序(x64)导致主例程之前发生崩溃,服务无法启动。卸载应用程序后,一切正常!
谢谢大家!