The first Windows service - the timer does not seem to tick

I wrote my first windows service.

  • Create a WS Project
  • Rename Service
  • Drag the timer to the middle
  • Turn it on, tick to 1 s
  • Create a logfie in teak if it does not exist
  • Install service
  • Start the service

Nothing happens...

I try to connect to the service, it loads correctly, but with a breakpoint in it, it never hits.

Any ideas?


Code Timer:

private void timMain_Tick(object sender, EventArgs e)
{
    if (!File.Exists("C:/test.txt"))
    File.Create("C:/test.txt");
}

Code initialization:

private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.timMain = new System.Windows.Forms.Timer(this.components);
    // 
    // timMain
    // 
    this.timMain.Enabled = true;
    this.timMain.Interval = 1000;
    this.timMain.Tick += new System.EventHandler(this.timMain_Tick);
    // 
    // AuctionService
    // 
    this.CanShutdown = true;
    this.ServiceName = "AuctionService";

}

One word: File.Create only to check if the timer. Because of this, I was a little irrelevant =)

+3
source share
2 answers

, , . MSDN docs , , .

System.Threading.Timer, :

Timer t = new Timer(t_Tick, null, 0, 1000);

, tick object.

+12

? . VS . , , , .

+3

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


All Articles