?
Solved

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

Posted on 2006-11-26
3
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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