Using TopShelf for windows service

Windows service runs continuously in the background and more often used as a back-end job. Its a pain if you want to debug it,even though you use logger to capture all events.we either attach the service as a process and debug it. But TopShelf lets you eliminate all of these and allows you to debug like console  application.

Topshelf has a start and stop method just like a service and also an separate command to install windows service with ease.

DocLink : https://topshelf.readthedocs.io/en/latest/installation/index.html

 

Object Comparisons — Difference between Equals method and ==

When we compare two objects with same content,there is a difference between “Equals and  == “.

Equals :

The Equals method does the content based comparison between two objects.

== :

“==” compares only object references.

Scenarios :


Sample s = new Sample () { a = "Hey" };
Sample s1 = s;
Sample s4 = new Sample () { a = "Hey" };

 Console.WriteLine(s1==s);  // True --Compares the instances 

Console.WriteLine(s==s4); // False ---Eventhough content is same,still == looks only for reference.

Console.WriteLine(s.Equals(s4)); // True --- Compares the value in field "a"  in both object and returns true.

String is an exceptional case and its immutable. It behaves with == as Equals.

 

 

 

 

 

 

WebHook in .NET

What is WebHook ?

A webhook is a provider that helps you to get data from external system  as and whenit flows into the system.These are real time data that is exposed over HTTP as and when data flows into system.

Components in WebHook :

Receiver : This type of webhook pulls the data  from external system to your server.

Sender  : This type of webhook is responsible for exposing your data to external system.

WebHook with .NET :

.NET does support web hook and there are various type of web hook that is customized  according to business need.

Types of WebHook Libraries provided by .NET :

  1. GitHubWebHook.
  2. SlackWebHook.
  3. GenericWebHook (This is the one which you use at custom level,the webhook is not tied to any providers like github,stripe instead you can define/customize  to your needs)

References :

https://github.com/aspnet/WebHooks

SetInterval and ClearInterval -Javascript

I had been developing a real time chat system at my work  and the chat system takes some time to load(makes an ajax call to the backend that fetches users details,chat message,chat room id ,chat user role id etc..).and also there are multiple chat rooms based on user roles. The challenge was to wait for all of data to load  and then enable the chat system.

Solution :

The solution  is to wait for x interval of time and then make a call x time to check if the data we require is loaded.

 


var intialloading=false;
waitoperation();
var someinterval =setInterval(function(){

if(intialloading)

{

//clear the interval.

ClearInterval(someinterval);

}

},2000) // call function every 2 secs

function waitoperation()

{

//some call

intialloading=true;

}