Help required - concept explanation

hi all,

I’m grappling with ExtendedTimers. Here’s what I want to achieve:

On a timed basis, redraw the LCD display (multiple seconds apart). Periodically though, other things will occur that require the redraw to happen immediately.

So I was thinking, create a funciton that redraws the LCD, and call that both using a timer and as needed when the other events happen.

Here’s where I came unstuck. If I define my redraw function as:

        public static void Display_Repaint() 

how do I go about defining the ExtendedTimer function ?
DisplayUpdate = new ExtendedTimer(new TimerCallback(Display_Repaint), null, 2000, 1000);

If I do this, then an error is shown - basically I understand that system.threading.timercallback needs a parameter (and I’m unsure what that parameter actually is?)

If I change the redraw to be Display_Repaint(Object o) then in the two or three places I need to call the redraw, what “object” do I need to provide?

So if someone could explain the concept that is going on here, that would help greatly - what is the “object” and what can I (or what should I) use it for within the redraw function (if anything).

I guess one alternative I considered that might get me out of this predicament is to move to a pure “handler” scenario, where the timer fires more frequently and it looks for a global redraw flag and if set it calls the redraw function, and if the normal redraw interval has passed it also calls the redraw function. What are people’s thoughts on whether these are better approaches?

Take a look at my ‘LCDLiveText’ project. Is uses an extended timer to repaint the LCD in response to scrolling, flashing, printing, etc. It also fires events for key presses. It may work for you as is or would be a good jumping off point. The code is hosted on CodePlex, the link to download via SVN is given on the project page.

(link removed)

One thing that just occurred to me tonight is that it might be nicer to map the LCD keypad to make them function as regular keyboard keys (just like if you had a keyboard plugged in.) I’m not quite sure how to accomplish that yet but it might make interacting with the keypad a bit easier.

Thanks Jeff for the comments. Yeah, I have looked at your code, but it’s still the “concept” that eludes me :-[

Your code is very similar to what I describe as my “alternate” solution near the end - you have a handler that calls the printbuffer code if needed. I guess the real piece I am missing is what does “target” do in your handler: updateTimerHandler(object target) ? It doesn’t seem to be referred to explicitly in your handler, but is it somehow implied? I am kind of guessing that I can just ignore the object and things will work as I need (since all the actual items I act on are within scope)

Event handlers always have some sort of argument they accept that tells them something about who generated the event and why. For example an event handler for mouse movements would want to know not just that the mouse moved but also where it is now. It seems that these event arguments are generally a simple class that encapsulates what ever info the handler might need to know.

The ExtendedTimer class allows you to provide a reference to any object you want for the argument. You can choose to use this functionality or not, but since the ExtendedTimer class is set up to expect its callback function to accept an object argument you have to include it and just set it to null in your constructor is your not using it.

Since it is an object reference you could use it for a variety of things. Let’s say you have a single handler handling multiple timer events so you might need to know which timer your handling. Since I was only interested in doing something on each tick of the timer I had no use for the passed object argument.