Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Topshelf TimeoutException

As a First step I created Windows Service project configured it properly and

On second Step I have added TopShelf Version 3.1.135.0 in my project If I run my service through (F5 Run) then it is loading Top-shelf Console and service is completed successfully.

However When I am running it to install and Start it from command prompt I am having below TimeOut Error.

Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.Service
Process.TimeoutException: Time out has expired and the operation has not been co
mpleted.



 public class AppService
    {
        LoggingService loggingService = new LoggingService(typeof(AppService).Name);


        public void Start()
        {
            loggingService.Info("SampleService is Started");
            ExtractProcess.Start();
            TransformProcess.Start();

        }

        public void Stop()
        {
            loggingService.Info("SampleService is Stopped");

        }
    }

-- Updated Code to fix this issue

 public void Start()
    {
        loggingService.Info("MPS.GOA.ETLService  is Started");
        ThreadStart myThreadDelegate = new ThreadStart(StartService);
        Thread myThread = new Thread(myThreadDelegate);
        myThread.Start();

    }

private void StartService()
{
    timer.Elapsed += new System.Timers.ElapsedEventHandler(OnElapsedTime);
    timer.Interval = 60000 * ServiceIntervalInMinutes;     //1 minute 60000 milliseconds
    timer.Enabled = true;
    Process();
}

private void Process()
{
    ExtractProcess.Start();
    TransformProcess.Start();
}

Any Suggestions? Time Out Error

like image 558
sandeeMPS Avatar asked Jan 14 '15 10:01

sandeeMPS


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

This error is happening because you are running the extract and process methods in the Start method of the service. This is OK in Visual Studio, but when you install the service and start it, the Service Control Manager waits for the Start method to return, and if it does not do so within a certain time (30 seconds by default) then it will return this error.

You have several options, all of which will allow the Start method to return immediately:

  1. Invoke the extract and transform methods on a separate thread
  2. Invoke the extract and transform methods asynchronously
  3. Use a timer to start the extract and transform process
like image 153
stuartd Avatar answered Sep 29 '22 07:09

stuartd