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
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");
begin();
}
void begin()
{
led.GreenBlueSwapped = true;
led.TurnBlue();
LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
//clear bitmap
LCD.Clear();
// 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
LCD.Flush();
// **** If I do not start the dispatcher **** I do not receive the button pressed event?
//dispatcherTimer.Start();
}
int i = 0;
static bool click = true;
void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
click = !click;
if (click)
{
dispatcherTimer.Start();
}
else
{
dispatcherTimer.Stop();
}
}
void dispatcherTimer_Tick(object sender, EventArgs e)
{
if(click)
{
led.TurnRed();
LCD.Clear();
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
LCD.Flush();
i++;
}
}
}
}
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