Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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