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

Command to obtain Ethernet/Wi-Fi/Bluetooth Mac Adress from the Windows Laptop


The below command will save all the mac details to MACDetails.txt file and saves in the desktop.

1. Click on Windows Start button.
2. In the Search field, type Command Prompt
3. Select Command Prompt in the Search results
4. Type this command: getmac /v > %userprofile%\desktop\MACDetails.txt
5. Hit Enter key.
6. Find the MACDetails.txt file on desktop.

How to Add/Remove View Engines in ASP.NET MVC


Here we will learn how to add/remove view engines in Asp.Net MVC.

Points covered:
1. Displaying the total available views
2. Clearing all the views
3. Adding the required views

Reading all the available view engines
using System.Web.Mvc;
 
namespace MVC.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public string Index()
        {
            string viewEngines = string.Empty;
            foreach (var item in ViewEngines.Engines)
            {
                viewEngines += item + "</br>";
            }
            return viewEngines;
        }
    }
}
Clearing all available view engines and adding required
using System.Web.Mvc;
using System.Web.Routing;
 
namespace MVC
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}

Happy coding..!

C# program to print triangle with different symbols and letters (smiley, copyright, star, numbers, alphabets) on console


Here in this post we are going to learn, how to print triangle on console using C#.net.

Outputs we are going to learn:

printing triangle with white smiley symbol on consoleprinting triangle with black smiley symbol on consoleprinting triangle with copyright symbol on consoleprinting triangle with star symbol on consoleprinting triangle with numbers on consoleprinting triangle with numbers on consoleimageimage

So we will print the above outputs on the console using C#.Net

How are we going to implement:

1. we will ask the user to enter Number of rows to print.

2. then we will print the pattern

3. to print the special symbols like smiley and copyright I have used Unicode characters and for that we need to mark output encoding as below

Marking output encoding
Console.OutputEncoding = System.Text.Encoding.UTF8;

4. I have given only 3 examples with symbols and if you want to try with more you can get the Unicode characters from the below link

https://www.compart.com/en/unicode/category/So?page=4

Triangle with Star symbol
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write("*");
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with numbers
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write(i);
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangel with numbers
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write(starCount);
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with Copyright symbol
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write('\u00A9');
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with black smiley
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write('\u263A');
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with white smiley
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write('\u263B');
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with alphabets
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            int ascii = 65;
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write(Convert.ToChar(ascii + starCount));
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Triangle with alphabets
using System;

namespace AlgorithamsAndLogics
{
    class TrianglePattern
    {
        static void Main(String[] args)
        {
            int ascii = 65;
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine("Howmany number of rows do you want to print?");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= numberOfRows; i++)
            {
                int starCount = 0;
                for (int j = 1; j <= numberOfRows – i; j++)
                {
                    Console.Write(" ");
                }
                while (2 * i – 1 != starCount)
                {
                    Console.Write(Convert.ToChar(ascii + i – 1));
                    starCount++;
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:

image

Happy coding..!

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..!

how to check an array is empty or not in javascript


To check the array is empty or not, we need to follow these steps

  1. Check whether the array is undefined or not.

    • first we need to check for the array is defined or not i.e initialized or not as follows
    •  
      var arr = [];
      if(arr != undefined)

  2. Check whether the array is null or not.

    • if we are getting data from remote source we need to check for null as follows

    • var arr = [];
      if(arr != undefined && arr != null)

  3. Check whether the type is object or not.

    • to avoid type related problems we need to check for the type as follows

    • var arr = [];
      if(arr != undefined && arr != null && typeof(arr) == typeof([]))

  4. Check whether the length of the array using length property.

    • If we want to check whether the array is having data or not we can use length property on array

    • var arr = [];
      if (arr != undefined && arr != null && typeof (arr) == typeof ([]) && arr.length > 0)

Full Example

var arr = [];
if (arr != undefined && arr != null && typeof (arr) == typeof ([]) && arr.length > 0) {
    //TODO: if the array has something in it
}
else {
    //TOTO: if the array is empty or null or undefined
}

 

Happy coding..!!