Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Every.One!

I need to check the value of a variable for if it has changed or is constant(slight variation allowed) in fixed duration of time(say 2sec).

I thought of running a parallel thread that keeps checking the variable after a certain sleep() duration but that slows down the application.

Any other idea?

Thanks!
Posted
Comments
Sergey Alexandrovich Kryukov 12-Jun-11 16:29pm    
What do you need for a trigger of this check? A time or an addressing of this variable? Also, why? What's the ultimate purpose of this technique?
Checking in thread is really bad. But answer my questions first?
--SA
AmarjeetAlien 13-Jun-11 1:41am    
What do you need for a trigger of this check?
->A slightly constant value of this variable over a small duration of time.
A time or an addressing of this variable?
->Both.I think.
why? What's the ultimate purpose of this technique?
->Please read the comments of you answer(--SA) on this thread:http://www.codeproject.com/Questions/209985/How-to-manually-set-mouse-events

1 solution

I guess you could use a timer. This timer shouldn't slow your application:

http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^]

But why this approach?
Isn't it easier to use a property which fires an event when the value changes (when variation is more than x%)?
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 12-Jun-11 16:29pm    
So what? How it solves the problem?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900