Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

690 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