Solved

Need quick answer; increment/decrement values in a windows service

Posted on 2006-11-26
3
208 Views
Last Modified: 2010-04-16
Hello experts,

I can probably test this by myself but I have no time for it so here's my question:

If I set an integer variable in the code of a windows service project type and increment or decrement its value according to a timer event, will I get the modified value when the timer fires the next time?

Thank you
0
Comment
Question by:bozer
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 18015251
Do you mean change the value when the timer event fires? Yes, the value will be different the next time the event fires, as long as the variable is defined outside the scope of the timer event (i.e. private variable to the service class, not declared internally in timer event method)
0
 

Author Comment

by:bozer
ID: 18015291
So if I have an integer called i whose value is 0, I increment it by one in the code. There's a timer event that fires say every 10 minutes, after half an hour the variable i becomes 3 right?

Thanks Nightman
0
 
LVL 29

Accepted Solution

by:
Nightman earned 125 total points
ID: 18015302
Yes, that is correct. Like I said, the key thing here is the scope - as long as the variable is defined outside of the delegate for the timer it will work fine. If it is defined inside the delegate it will be re-initialised every time the timer fires.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question