Error 1061 the service cannot accept control messages at this time : Topshelf


I have deployed the windows service built with Topshelf host and when I try to stop it, it is throwing the below error
“Error 1061 the service cannot accept control messages at this time” 

Here I have observed the below behaviors:

  1. When I am running in my local machine with Visual Studio, working fine without any errors.
  2. When I am running in my local machine as a service it is throwing the above error and showing the status as stopping and it is getting stopped after some time (30 mins)
  3. When I am running this in my server as a service it is throwing the above error and not stopping.

Then I found the below power shell code to stop the service here.

#Get the PID of the required service with the help of the service name, say, service name.
$ServicePID = (get-wmiobject win32_service | where { $_.name -eq 'service name'}).processID 

#Now with this PID, you can kill the service
taskkill /f /pid $ServicePID

 

Advertisements

C# program to reverse a number


Here in this post we are going to learn how to reverse a number using C#.Net

What is reverse a number:

If user enters the number 12345, and if we reverse this number we will get 54321 as a reversed number.

So here 12345 is a number entered by user and 54321 is a reversed number.

What can we cover in this program:

1. we will ask user to enter a number on the console

2. we will read the number entered by the use and reverse that number

3. we will print the enter number and reversed number on the console

Reverse number program:

Code Snippet 1
using System;

namespace AlgorithamsAndLogics
{
    class ReverseNumber
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a number to reverse!");
            int number = Convert.ToInt32(Console.ReadLine());
            int tempnumber = number;
            int reverseNumber = 0;
            while (tempnumber > 0)
            {
                var remainder = tempnumber % 10;
                reverseNumber = reverseNumber * 10 + remainder;
                tempnumber = tempnumber / 10;
            }
            Console.WriteLine($"Actual number: {number}");
            Console.WriteLine($"Reversed number: {reverseNumber}");
        }
    }
}

Output:

image

Happy coding..!