user2289486
user2289486

Reputation: 11

Windows Service Variable Lifetime

I would like to understand the Variable lifetime on a Windows service.

I have a SQL table where a temporary table stores both INFLOW and OUTFLOW records for my application.

I declared two global variables like below and to this variable i assign the Row Id from the temporary table. int iTempKeyInflow = 0; int iTempKeyOutflow = 0;

On elapsed time do i loose this values that the service was handling in the previous run.

Basically if the timer expires before the completion of execution of a cycle, does the service cycle still run in background. So can i handle 100 records in a second from the table?

Upvotes: 1

Views: 2020

Answers (1)

Avner Shahar-Kashtan
Avner Shahar-Kashtan

Reputation: 14700

A Windows Service doesn't introduce any more lifetime complexities than any other program. The only difference is that it runs quietly in the background.

A .NET application implementing a Windows Service inherits the ServiceBase class and overrides the OnStart method. That's the extent of the API. The OnStart method is in charge of everything else - if it simply exits, then the service exits as well. If it spawns a new background thread or task to perform its work, then that thread will continue to exist.

A variable defined in OnStart will go out of scope when that method exits. One defined in the class scope, or in the scope of a class that's called from OnStart, will be tied to the lifetime of that class instance.

Without knowing exactly where you're defining your variables, we can't tell you what their lifetime will be, but chances are that running as a Windows Service won't be the deciding factor.

Upvotes: 1

Related Questions