Solved

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

Posted on 2006-11-26
3
199 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now