简体   繁体   English

发生错误1053,服务未及时响应启动或控制请求

[英]Im getting Error 1053 the service did not respond to the start or control request in a timely fashion

I'm trying to create window service which sends mail to me when specific type of file came in the folder.While running the service i'm getting error like 'Error 1053- the service did not respond to the start or control request in a timely fashion. 我正在尝试创建窗口服务,当文件夹中包含特定类型的文件时,该窗口服务会向我发送邮件。在运行服务时,我收到类似错误``1053的错误'',该服务未响应启动或控制请求及时的时尚。 Please help me to resolve this error.' 请帮助我解决此错误。” I will be more thankful for you. 我会更加感谢你。

I have written code as below: 我写了如下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;
using System.ServiceProcess;
using System.Timers;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace DUP1
{
    class BrlCode
    {
        public void brlCount()
        {
            String[] files = Directory.GetFiles(@"H:\\EDI", "*.brl", SearchOption.AllDirectories);
            if (files.Length > 0)
            {
                var clientDomain = ConfigurationManager.AppSettings.Get("clientDomain");
                var from = ConfigurationManager.AppSettings.Get("from");
                var to = ConfigurationManager.AppSettings.Get("to");
                MailMessage mm = new MailMessage(from, to);
                mm.Body = ConfigurationManager.AppSettings.Get("body");
                mm.Subject = ConfigurationManager.AppSettings.Get("subject2");
                int leng = files.Length;
                for (int i = 0; i < files.Length; i++)
                {
                    String sep = "   |  ";

                    String Body1 = string.Join(sep, files, 0, leng);
                    mm.Body = Body1;

                }

                var smtp1 = new SmtpClient(ConfigurationManager.AppSettings.Get("clientDomain"));
                smtp1.Port = 25;

                //setting default credentials

                smtp1.Credentials = CredentialCache.DefaultNetworkCredentials;
                smtp1.EnableSsl = false;
                smtp1.Send(mm);

            }
        }
    }

}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;
using System.ServiceProcess;
using System.Timers;

namespace DUP1
{
    public partial class Service1 : ServiceBase
    {
        private Timer timer1 = null;

        public Service1()
        {
            this.OnStart(null);
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            timer1 = new Timer();
            this.timer1.Interval = 540000;
            //Log("Service Started successfully");
            BrlCode bc = new BrlCode();

            bc.brlCount();
        }
        }


    }
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Mail;
using System.Configuration;
using System.IO;
using System.Timers;



namespace DUP1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 

                new Service1() 
            };
            ServiceBase.Run(ServicesToRun);
            Console.Write("yahoo");
            Console.ReadLine();
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

  <system.web>
    <authorization>
      <allow users="dipsk4@gmail.com" />

    </authorization>
  </system.web>
  <appSettings>

    <add key="clientDomain" value="mail.allstate.com"/>
    <add key="directory" value="H:\\"/>
    <add key="from"  value="dipsk4@gmail.com"/>
    <add key="to"  value="dipsk4@gmail.com"/>
    <add key="body"  value="01 .lnr files has been received"/>
    <add key="subject1" value="LNR files"/>
    <add key="subject2" value="BRL files"/>
    <add key="subject3" value="DUP files"/>
    <add key="attachment"  value="H:\\deep.txt"/>
  </appSettings>
</configuration>

You should try offloading the work done by BrlCode in a different thread so that OnStart can return as fast as possible. 您应该尝试将BrlCode完成的工作分流到另一个线程中,以便OnStart可以尽快返回。

protected override void OnStart(string[] args)
{
  timer1 = new Timer();
  this.timer1.Interval = 540000;

  //Log("Service Started successfully");

  Task.Run(() => 
  {
    BrlCode bc = new BrlCode();
    bc.brlCount();
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 1053 服务没有及时响应启动或控制请求 - Error 1053 the service did not respond to the start or control request in a timely fashion 错误1053:服务未及时响应启动或控制请求 - Error 1053: the service did not respond to the start or control request in a timely fashion Windows服务无法启动&#39;错误1053:服务未及时响应启动或控制请求&#39; - Windows Service won't start 'Error 1053: The service did not respond to the start or control request in timely fashion' 启动服务:“错误1053:服务未及时响应启动或控制请求” - Starting a service: “Error 1053: The service did not respond to the start or control request in a timely fashion” 错误 1053:安装并运行 WCF 服务时,服务未及时响应启动或控制请求 - Error 1053: The service did not respond to the start or control request in a timely fashion, when intalled and ran a WCF service C#错误1053,服务未及时响应启动或控制请求 - C# Error 1053 the service did not respond to the start or control request in a timely fashion 错误 1053:服务没有使用 FileSystemWatcher 及时响应启动或控制请求 - Error 1053:The service did not respond to start or control request in timely fashion with FileSystemWatcher 1053 windows服务没有及时响应 - 1053 windows service did not respond in timely fashion 安装Windows服务时出错 - 服务未及时响应启动或控制请求 - Error installing Windows service — The service did not respond to the start or control request in a timely fashion 服务错误1053:无法及时启动 - Service Error 1053: Could not start in timely fashion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM