What is the accepted way to write C # TSR?

I use C # to write a WCF router that I want to keep working without using Console.ReadKey "hack". I was wondering if there is an acceptable way to do this in C #, which is more elegant than

while (true)
    Thread.Sleep(100);
+3
source share
2 answers

create a project windows service. Windows services have a consistent life cycle compared to the standard Windows client.

You can start here .

From msdn:

. . , , "". Start OnStart , .

A running service can exist in this state indefinitely until it is either stopped or paused or until the computer shuts down. : "", "" "" . , , .

+7

, ManualResetEvent?

ManualResetEvent stopEvent = new ManualResetEvent(false);

public void StartService()
{

     service.Open();
     stopEvent.WaitOne()
}

stopEvent.Set(), .

+3

Source: https://habr.com/ru/post/1748791/


All Articles