c# - 服务错误 1053 : Could not start in timely fashion

标签 c# windows winforms service installshield

在你问之前,是的,我在这个问题上搜索了又搜索,尝试了其他人为他们所做的工作,但一无所获。我试过:

  • 以 Release模式运行
  • 在 LocalSystem、LocalService 和命名帐户上运行
  • 我的项目中没有调试代码

我的项目的摘要是一个 Windows 服务,它扫描源文件夹中的文件并在设定的时间转换它们并将它们放置在目标文件夹中。这些设置可以在 GUI 中更改,GUI 会更改服务定期扫描的 XML 文件。

成品包装在 InstallShield 中。一切都在 VisualStudio 中运行。我可以安装该程序并且服务完美运行。当我获取发布版本并将其安装在同一台机器上时,我收到此 1053 错误。

这是我的OnStart

    protected override void OnStart(string[] args)
    {
        // Update the service state to Start Pending.
        ServiceStatus serviceStatus = new ServiceStatus();
        serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
        serviceStatus.dwWaitHint = 100000;
        SetServiceStatus( this.ServiceHandle, ref serviceStatus );

        // Set up a timer to trigger every 30s
        System.Threading.Thread t1 = new System.Threading.Thread( new System.Threading.ThreadStart( this.InitTimer ) );
        t1.Start();

        // Set folders and time from xml
        System.Threading.Thread t2 = new System.Threading.Thread( new System.Threading.ThreadStart( this.InitSettings ) );
        t2.Start();

        // Update the service state to Running.
        eventLog1.WriteEntry( "Service successfully started", EventLogEntryType.Information, eventId++ );
        serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
        SetServiceStatus( this.ServiceHandle, ref serviceStatus );
    }

这是我的主要内容

    public WTVService(string[] args)
    {
        InitializeComponent();
        string eventSourceName = "Searcher";
        string logName = "WTVConverter";
        if ( args.Count() > 0 )
        {
            eventSourceName = args[0];
        }
        if ( args.Count() > 1 )
        {
            logName = args[1];
        }
        eventLog1 = new EventLog();
        if ( !EventLog.SourceExists( eventSourceName ) )
        {
            EventLog.CreateEventSource( eventSourceName, logName );
        }
        eventLog1.Source = eventSourceName; eventLog1.Log = logName;
    }

让我知道哪些其他信息可能有帮助。

编辑:此外,如果它有所不同,错误会立即出现,而不是在假定的 30 秒超时规则之后。

最佳答案

所以这很有趣。我确定 InstallShield 人群在这里有点受限,但这可能会对某些人有所帮助。最终起作用的是将构建模式从 SingleImage 更改为 DVD-5。我不能说为什么,但它现在工作得很好。我在一台以前从未运行过我的程序的机器上进行了测试,一切正常。

关于c# - 服务错误 1053 : Could not start in timely fashion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33073233/

相关文章:

c# - 生成集合的排列 - 高效且有区别

c++ - 在 C/C++ 中使用字符串——[ ] 在 LPCTSTR 之后

java - 是否可以知道 JFrame 是否完全可见?

c# - Windows 窗体中的 WPF

c# - 从存储桶 xxx 获取对象文件名.xlsx 时出错。确保它们存在并且您的存储桶与此功能位于同一区域?

c# - 在 ASP.NET Identity 2 中哪里可以找到生成的 PasswordReset token ?

c# - RegisterPowerSettingsNotification C# pinvoke

c++ - 发生内存不足错误时怎么办?

c# - winforms - 状态栏标签的工具提示未显示

c# - 防止控件在禁用时变灰