Solution for regularly running the .NET component on Windows

I need to write some .NET code that runs at regular intervals in order to check the "raw" elements in a table in a database, process them, and then write back to the database they are processing. We will probably set it up to work every minute.

How can I configure a component in a Windows Server environment to run code on a periodic basis?

+3
source share
4 answers

Use System.Timers.Timer in your Windows service.

You may have code like this (from MSDN) in your Windows OnStart service:

// Hook up the Elapsed event for the timer.
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

// Set the Interval to 2 seconds (2000 milliseconds).
timer.Interval = 2000;
timer.Enabled = true;

...........

// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
    ......
}

, , , Windows. ( , ).

+3

Windows. .NET EXE ( , EXE) . , , , Windows.

+3

Windows (start-programs-accessories-system tools)... SSIS... (Activebatch ..)...

+2

, , ( , , ), Windows.

Windows, Start() :

Timer tmr = new Timer(60000, true) //this could be wrong: set it for one minute and turn on auto-reset.

tmr.Start();

Timer ( : Tick, ?), .

, , false, , .

+1

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


All Articles