.net micro framework dispatcherTimer relation to button events

Not sure if this is the proper place to ask but here goes…

I will start by saying, Yes it is true. I do not fully understand the dispatcher.

I have a small test application that I am using just to fool around with fonts and I included a dispatch timer for possible use for updating the LCD.

My question is why do I not receive button events if after creating the dispatch timer and I do not start it.

Sample code

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerFontTest
    public partial class Program
        Bitmap LCD;
        Font NBFont;
        Font smallfont;
        Font blockfont;
        DispatcherTimer dispatcherTimer;
        void ProgramStarted()
            button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);

            NBFont = Resources.GetFont(Resources.FontResources.NinaB);
            smallfont = Resources.GetFont(Resources.FontResources.small);

            // Font webdingg was created at 8 points which is slightly larger than the standard small font
            // Old eyes here so i'll just say it appears to be one pixel greater in height
            blockfont = Resources.GetFont(Resources.FontResources.webdingg);

            dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

        void begin()
            led.GreenBlueSwapped = true;

            LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            //clear bitmap
            // print some text
            LCD.DrawText("Y=20 ABCabcDEFdefGHIghiJKLjklMNOmnoPQRpqrSTUstuVWXYZvwxyz", NBFont, Colors.Red, 1, 20);
            LCD.DrawText((0x67).ToString(), blockfont, Colors.Blue, 120, 20);

            LCD.DrawText("Y=43 ABCabcDEFdefGHIghiJKLjklMNOmnoPQRpqrSTUstuVWXYZvwxyz", smallfont, Colors.Yellow, 1, 43);
            LCD.DrawText("Y=50 ABCabcDEFdefGHIghiJKLjklMNOmnoPQRpqrSTUstuVWXYZvwxyz", smallfont, Colors.Yellow, 1, 50);
            LCD.DrawText("Y=57 ABCabcDEFdefGHIghiJKLjklMNOmnoPQRpqrSTUstuVWXYZvwxyz", smallfont, Colors.Yellow, 1, 57);

            LCD.DrawText((0x67).ToString(), blockfont, Colors.Blue, 120, 49);

            //transfer the bitmap to the display

            // **** If I do not start the dispatcher **** I do not receive the button pressed event?



        int i = 0;
        static bool click = true;
        void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
            click = !click;
            if (click)

        void dispatcherTimer_Tick(object sender, EventArgs e)

                LCD.DrawText("Y=50 ABCabcDEFdefGHIghiJKLjklMNOmnoPQRpqrSTUstuVWXYZvwxyz", smallfont, Colors.Yellow, 1, 50);
                LCD.DrawText((0x67).ToString(), blockfont, Colors.Blue, i, 49);

                //transfer the bitmap memory to the display

I ‘think’ that I have created a dispatch timer if the past without starting it right away and my application received events.
Not sure now…

Thanks for any thoughts you may have. I would like to understand why I must start the timer in order to receive other events.
I ‘thought’ dispatcher ran in it’s own thread?

Have a GREAT day

I am not sure what DispatcherTimer is? Try using GT.Timer.


Thanks for the reply.

My question relates to use of the dispatcher and why I do not receive the button event without starting the dispatch timer.

I do not need to make anything in the sample code to work. The code shown here is only a test for something I want to do in another application.

Look at the generated code to see what it shows.

I am on a train now, and have no access to Gadgeteer documentation, so I can not lookup what a DispatchTimer is/does.

But, if I was to do what you are trying to do, I would use a GT.Timer.

Can you tell me what a DispatchTimer does that is different from GT.Timer?


When your program inserts a DispatcherTimer object (timer) into the queue of a Dispatcher object (dispatcher), the dispatcher processes the timer at a specified time interval. If the dispatcher is processing a large number of messages, the timer might not be evaluated at the expected time.

ok, I understand.

I think the issue may be a function of mixing Gadgeteer and regular MF API calls. Gadgeteer has its own dispatcher.

Try using the GT.Timer.