none
Error 1053: The service didnot respond to the start or control request in a timely fashion RRS feed

  • Question

  • Hello Everyone,

    I have written one windows service in which i am continuously connecting to the database to check for the request.

    In start method of the service class i am calling a method which is having a while loop which continuously checks for the request in the database. Following is my code

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Net.Mail;
    using System.Diagnostics;
    
    
    using DataBaseLayer;
    using System.IO;
    
    namespace ServiceEngine
    {
      class MyServer
      {
        public void start()
        {
          ConnectionState Description = 0;
          CommonClass objClsCommon = new CommonClass();
          SchedulerRequests objScheduler = new SchedulerRequests();
          ATGSchedulerRequests objATGScheduler = new ATGSchedulerRequests();
          if (InternetGetConnectedState(ref Description, 0))
          {
            Console.ForegroundColor = ConsoleColor.White;
            Connections objConnection = new Connections();
            //PollEngine objPollEngine = new PollEngine();
    
    
            bool bRunScheduler = false;
            int iCurrentMin = DateTime.Now.Minute;
            int iTempMin;
    
            string sSource;
            string sLog;
            string sEvent;
    
            sSource = "Service Engine";
            sLog = "Application";
            sEvent = "Sample Event";
    
            if (!EventLog.SourceExists(sSource))
              EventLog.CreateEventSource(sSource, sLog);
    
            EventLog.WriteEntry(sSource, "Before Database connecting");
            EventLog.WriteEntry(sSource, "Before Database connecting", EventLogEntryType.Information, 234);
    
            SqlParameter objInputCommandParams = new SqlParameter("@serviceEngineStatus", SqlDbType.Bit);
            objInputCommandParams.Value = true;
            SqlHelper.ExecuteNonQuery(Connections._ConnString, CommandType.StoredProcedure, "stp_ServiceEngineStatus", objInputCommandParams);
    
            EventLog.WriteEntry(sSource, "Database connected");
            EventLog.WriteEntry(sSource, "Database connected", EventLogEntryType.Information, 234);
            Console.WriteLine("Waiting For Clients....\n");
            while (true)
            {
    
              try
              {
                SetConsoleCtrlHandler(new ControlEventHandler(OnControlEvent), true);
                if (InternetGetConnectedState(ref Description, 0))
                {
    
                  SqlParameter[] objParams = new SqlParameter[35];
    
                  objParams[0] = new SqlParameter("@iCUSRCardUpdateId", SqlDbType.Int, 4);
                  objParams[0].Direction = ParameterDirection.Output;
    
                  objParams[1] = new SqlParameter("@vCUSRSiteId", SqlDbType.VarChar, 20);
                  objParams[1].Direction = ParameterDirection.Output;
    
                  objParams[2] = new SqlParameter("@vCUSRUserName", SqlDbType.VarChar, 30);
                  objParams[2].Direction = ParameterDirection.Output;
    
                  objParams[3] = new SqlParameter("@iRCRRequestId", SqlDbType.Int, 4);
                  objParams[3].Direction = ParameterDirection.Output;
    
                  objParams[4] = new SqlParameter("@vRCRSiteId", SqlDbType.VarChar, 20);
                  objParams[4].Direction = ParameterDirection.Output;
    
                  objParams[5] = new SqlParameter("@vRCRUserId", SqlDbType.VarChar, 30);
                  objParams[5].Direction = ParameterDirection.Output;
    
                  objParams[6] = new SqlParameter("@vSBRRSiteId", SqlDbType.VarChar, 3);
                  objParams[6].Direction = ParameterDirection.Output;
    
                  objParams[7] = new SqlParameter("@vSBRRUserId", SqlDbType.VarChar, 30);
                  objParams[7].Direction = ParameterDirection.Output;
    
                  objParams[8] = new SqlParameter("@cSBRRBackupOrRestore", SqlDbType.Char, 1);
                  objParams[8].Direction = ParameterDirection.Output;
    
                  objParams[9] = new SqlParameter("@iSBRRRequestId", SqlDbType.Int, 1);
                  objParams[9].Direction = ParameterDirection.Output;
    
                  objParams[10] = new SqlParameter("@vCBRRSiteId", SqlDbType.VarChar, 3);
                  objParams[10].Direction = ParameterDirection.Output;
    
                  objParams[11] = new SqlParameter("@vCBRRUserId", SqlDbType.VarChar, 30);
                  objParams[11].Direction = ParameterDirection.Output;
    
                  objParams[12] = new SqlParameter("@cCBRRBackupOrRestore", SqlDbType.Char, 1);
                  objParams[12].Direction = ParameterDirection.Output;
    
                  objParams[13] = new SqlParameter("@iCBRRRequestId", SqlDbType.Int, 1);
                  objParams[13].Direction = ParameterDirection.Output;
    
                  objParams[14] = new SqlParameter("@iPollingPollId", SqlDbType.Int, 3);
                  objParams[14].Direction = ParameterDirection.Output;
    
                  objParams[15] = new SqlParameter("@vPollingSiteId", SqlDbType.VarChar, 30);
                  objParams[15].Direction = ParameterDirection.Output;
    
                  objParams[16] = new SqlParameter("@vPollingUserId", SqlDbType.VarChar, 30);
                  objParams[16].Direction = ParameterDirection.Output;
    
                  objParams[17] = new SqlParameter("@vTerminalSiteId", SqlDbType.VarChar, 30);
                  objParams[17].Direction = ParameterDirection.Output;
    
                  objParams[18] = new SqlParameter("@vSendCommand", SqlDbType.VarChar, 100);
                  objParams[18].Direction = ParameterDirection.Output;
    
                  objParams[19] = new SqlParameter("@vConnectionType", SqlDbType.VarChar, 30);
                  objParams[19].Direction = ParameterDirection.Output;
    
                  objParams[20] = new SqlParameter("@vTerminalUserId", SqlDbType.VarChar, 50);
                  objParams[20].Direction = ParameterDirection.Output;
    
                  objParams[21] = new SqlParameter("@vATGSiteId", SqlDbType.VarChar, 3);
                  objParams[21].Direction = ParameterDirection.Output;
    
                  objParams[22] = new SqlParameter("@iATGPollId", SqlDbType.Int, 1);
                  objParams[22].Direction = ParameterDirection.Output;
    
                  objParams[23] = new SqlParameter("@vATGPollUserId", SqlDbType.VarChar, 30);
                  objParams[23].Direction = ParameterDirection.Output;
    
                  objParams[24] = new SqlParameter("@iATGRequestId", SqlDbType.VarChar, 30);
                  objParams[24].Direction = ParameterDirection.Output;
    
                  objParams[25] = new SqlParameter("@iCBRRPollId", SqlDbType.Int, 2);
                  objParams[25].Direction = ParameterDirection.Output;
    
                  objParams[26] = new SqlParameter("@vCUSRPollId", SqlDbType.Int, 2);
                  objParams[26].Direction = ParameterDirection.Output;
    
                  objParams[27] = new SqlParameter("@iSBRRPollId", SqlDbType.Int, 2);
                  objParams[27].Direction = ParameterDirection.Output;
    
                  objParams[28] = new SqlParameter("iSchedulerReq", SqlDbType.Int, 2);
                  objParams[28].Direction = ParameterDirection.Output;
    
                  objParams[29] = new SqlParameter("iATGSchedulerReq", SqlDbType.Int, 2);
                  objParams[29].Direction = ParameterDirection.Output;
    
                  objParams[30] = new SqlParameter("vCancellingSiteID", SqlDbType.VarChar, 50);
                  objParams[30].Direction = ParameterDirection.Output;
    
                  objParams[31] = new SqlParameter("vCancellingUserID", SqlDbType.VarChar, 50);
                  objParams[31].Direction = ParameterDirection.Output;
    
                  objParams[32] = new SqlParameter("@vCancellingAction", SqlDbType.VarChar, 50);
                  objParams[32].Direction = ParameterDirection.Output;
    
                  objParams[33] = new SqlParameter("@vSBRRLogDate", SqlDbType.VarChar, 30);
                  objParams[33].Direction = ParameterDirection.Output;
    
                  objParams[34] = new SqlParameter("@vSBRREmailLog", SqlDbType.VarChar, 200);
                  objParams[34].Direction = ParameterDirection.Output;
    
    
    
    
    
                  SqlHelper.ExecuteScalar(Connections._ConnString, CommandType.StoredProcedure, "stp_GetUpdatedRecordsForServiceEngine", objParams);
                  iTempMin = DateTime.Now.Minute;
    
                  if (iCurrentMin != iTempMin && !bRunScheduler && DateTime.Now.Second > 15)
                  {
                    bRunScheduler = true;
                    iCurrentMin = iTempMin;
                  }
    
                  if (bRunScheduler)
                  {
                    SqlHelper.ExecuteNonQuery(Connections._ConnString, CommandType.StoredProcedure, "stp_Scheduler");
                    bRunScheduler = false;
                  }
    
    
                  CardUpdate objCardUpdate = new CardUpdate();
    
                  if (objParams[0].Value != DBNull.Value && objParams[1].Value != DBNull.Value)
                  {
                    //Creating Thread for Card and Account Update Process
                    //if (!IsSchdulerRequest(objParams[2].Value.ToString(),objParams[1].Value.ToString(), objParams[26].Value.ToString(), CommonClass.UpdateCard))
                    //{
                    Thread thCardUpdate = new Thread(new ParameterizedThreadStart(objCardUpdate.CardUpdateIntoFsc));
                    thCardUpdate.Start((object)objParams);
                    //}
                  }
                  if (objParams[3].Value != DBNull.Value && objParams[4].Value != DBNull.Value)
                  {
                    //Creating Thread for Resending the All Cards to FSC
                    Thread thResendCard = new Thread(new ParameterizedThreadStart(objCardUpdate.ResendCards));
                    thResendCard.Start((object)objParams);
                  }
                  if (objParams[6].Value != DBNull.Value && objParams[7].Value != DBNull.Value && objParams[8].Value != DBNull.Value)
                  {
                    SiteBackupRestore objSiteBackupRestore = new SiteBackupRestore();
                    //Creating Thread for Site Backup and Restore Process
                    //if (!IsSchdulerRequest(objParams[7].Value.ToString(), objParams[6].Value.ToString(), objParams[27].Value.ToString(), CommonClass.BackupSystem))
                    //{
                    Thread thSiteBackupRestore = new Thread(new ParameterizedThreadStart(objSiteBackupRestore.SiteBackupFromRestoreToFSC));
                    thSiteBackupRestore.Start((object)objParams);
                    //}
                  }
                  if (objParams[10].Value != DBNull.Value && objParams[11].Value != DBNull.Value && objParams[12].Value != DBNull.Value)
                  {
                    CardBackupRestore objCardBackupRestore = new CardBackupRestore();
                    //Creating Thread for Site Backup and Restore Process
                    //if (!IsSchdulerRequest(objParams[11].Value.ToString(), objParams[10].Value.ToString(), objParams[25].Value.ToString(), CommonClass.BackupCard))
                    //{
                    Thread thCardBackupRestore = new Thread(new ParameterizedThreadStart(objCardBackupRestore.CardBackupFromRestoreToFSC));
                    thCardBackupRestore.Start((object)objParams);
                    //}
                  }
                  if (objParams[14].Value != DBNull.Value && objParams[15].Value != DBNull.Value && objParams[16].Value != DBNull.Value)
                  {
                    PollEngine objPollEngine = new PollEngine();
                    //Creating Thread for polling Process
                    //if (!IsSchdulerRequest(objParams[16].Value.ToString(), objParams[15].Value.ToString(), objParams[14].Value.ToString(), CommonClass.Polling))
                    // {
                    Thread obPollThread = new Thread(new ParameterizedThreadStart(objPollEngine.PollThread));
                    obPollThread.Start((object)objParams);
                    //}
                  }
                  if (objParams[17].Value != DBNull.Value && objParams[19].Value != DBNull.Value)
                  {
                    TerminalEngine objTerminalEngine = new TerminalEngine();
                    //Creating Thread for Terminal Engine Process
                    Thread obTerminalThread = new Thread(new ParameterizedThreadStart(objTerminalEngine.TerminalEngineConnection));
                    obTerminalThread.Start((object)objParams);
                  }
    
                  //if (objParams[21].Value != DBNull.Value && objParams[22].Value != DBNull.Value && objParams[23].Value != DBNull.Value)
                  //{
                  //  ATGPoll objATGPoll = new ATGPoll();
                  //  Thread thATGPoll = new Thread(new ParameterizedThreadStart(objATGPoll.PollGauge));
                  //  thATGPoll.Start((object)objParams);
                  //commented by senthil and on 2 mar 2009 and have one more condition next to below if
                  //}
    
                  if (!objParams[28].Value.ToString().Equals("0") && !CommonClass.bSchdulerRequestStarted)
                  {
                    CommonClass.bSchdulerRequestStarted = true;
                    Thread thSchedulerReq = new Thread(objScheduler.StartRequest);
                    //objScheduler.StartRequest(objSchedulerReq.ToString());
                    thSchedulerReq.Start();
                  }
    
                  if (!objParams[29].Value.ToString().Equals("0") && !CommonClass.bATGSchdulerRequestStarted)
                  {
                    CommonClass.bATGSchdulerRequestStarted = true;
                    //ATGPoll objATGPoll = new ATGPoll();
    
                    Thread thATGPoll = new Thread(objATGScheduler.StartRequest);
                    thATGPoll.Start();
                  }
                  if (objParams[30].Value != DBNull.Value && objParams[31].Value != DBNull.Value)
                  {
                    StreamWriter SW;
                    string path = "../CancelLogs/" + DateTime.Now.Year + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd");
                    if (!Directory.Exists(path))
                    {
                      Directory.CreateDirectory(path);
                    }
                    string fileName = objParams[31].Value.ToString() + objParams[30].Value.ToString() + objParams[32].Value.ToString() + "_" + DateTime.Now.Year + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd");
                    path = path + @"\" + fileName + ".txt";
                    SW = File.AppendText(path);
                    SW.WriteLine("\r\n" + DateTime.Now.ToString() + " : " + "Cancelling" + "\r\n");
                    SW.Close();
                  }
    
    
                }
                else
                {
                  Console.WriteLine("Please check TCP/IP cable. Couldn't find network.");
                }
              }
              catch (SqlException ex)
              {
                Console.WriteLine(ex.Message);
              }
              catch (Exception ex)
              {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
              }
    
    
    
            }
          }
          else
          { Console.WriteLine("Please check TCP/IP cable. Couldn't find network."); }
        }
    
        #region CheckingforInternet
        [DllImport("wininet.dll", CharSet = CharSet.Auto)]
    
        static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
    
    
    
        #endregion
    
        #region Sending Mail
    
        [DllImport("kernel32.dll")]
        static extern bool SetConsoleCtrlHandler(ControlEventHandler e, bool add);
    
    
        public delegate bool ControlEventHandler(ConsoleEvent consoleEvent);
    
        public enum ConsoleEvent
        {
          CTRL_C_EVENT = 0,
          CTRL_BREAK_EVENT,
          CTRL_CLOSE_EVENT,
          CTRL_LOGOFF_EVENT = 5,
          CTRL_SHUTDOWN_EVENT
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="consoleEvent"></param>
        /// <returns></returns>
        public static bool OnControlEvent(ConsoleEvent consoleEvent)
        {
          try
          {
    
            //SqlParameter[] objCommandParams = new SqlParameter[1];
    
            //objCommandParams[0] = new SqlParameter("@serviceEngineStatus", SqlDbType.Bit);
            //objCommandParams[0].Direction = ParameterDirection.Input;
            //objCommandParams[0].Value = false;
            //SqlHelper.ExecuteScalar(Connections._ConnString, CommandType.StoredProcedure, "stp_ServiceEngineStatus", objCommandParams);
    
            SqlParameter objCommandParams = new SqlParameter("@serviceEngineStatus", SqlDbType.Bit);
            objCommandParams.Value = false;
            SqlHelper.ExecuteNonQuery(Connections._ConnString, CommandType.StoredProcedure, "stp_ServiceEngineStatus", objCommandParams);
    
            string sTO = ConfigurationManager.AppSettings["TO"].ToString();
            string sCC = ConfigurationManager.AppSettings["CC"].ToString();
            string sBCC = ConfigurationManager.AppSettings["BCC"].ToString();
            string sFROM = ConfigurationManager.AppSettings["FROM"].ToString();
            string sBody = ConfigurationManager.AppSettings["BODY"].ToString();
            string sSub = ConfigurationManager.AppSettings["SUB"].ToString();
            string sHost = ConfigurationManager.AppSettings["HOST"].ToString();
    
    
    
            MailMessage message = new MailMessage();
            message.From = new MailAddress(sFROM);
            if (sTO.Equals(string.Empty))
            {
              Console.WriteLine("Please mention 'TO' Mail Address");
            }
            else
            {
              foreach (string TO in sTO.Split(';'))
              {
                message.To.Add(TO);
              }
            }
            if (!sCC.Equals(string.Empty))
            {
              foreach (string CC in sCC.Split(';'))
              {
                message.CC.Add(CC);
              }
            }
            if (!sBCC.Equals(string.Empty))
            {
              foreach (string BCC in sBCC.Split(';'))
              {
                message.Bcc.Add(BCC);
              }
            }
    
    
            message.Body = sBody;
            message.Subject = sSub;
    
            SmtpClient client = new SmtpClient(sHost);
            client.Send(message);
    
    
    
    
    
            //MessageBox.Show("Mails Sent");
            return true;
          }
          catch (Exception ex)
          {
            Console.WriteLine(ex.Message);
            Console.ReadKey();
            return true;
          }
        }
    
        #endregion
      }
    }
    
    

    .

     

     

     

    Windows could not start the service on local computer

    Error 1053: The service didnot respond to the start or control request in a timely fashion

     

    can anyone please let know what i can do on this?

    Thanks

    Anil Kumar

    Wednesday, November 10, 2010 5:55 PM