Asked By Matte
17-Oct-08 05:22 AM

Hello everyone!
I'm just starting .NET programming now and I have to start from the .NET
Micro Framework (never had experience on the 'regular' one).
I wrote a small class on a DeviceSolutions Tahoe board with .NET MF 3.0 Beta
2 firmware.
I control the PWM in a for loop and watch for the results. The PWM DOES
respond (I see the avg ouput change with a multimeter), I see the code
running smoothly through Debug statements, but the Text control in the GUI is
not updating while I stay in the loop. It does update when I exit the loop,
but then I only see the last state I've been through, while I wanted it to
report on each change.
Here is the code:
public void OutputA()
{
Text text = ((Text)((Panel)MainWindow.Child).Children[0]);
Meridian.PWM modulator;
byte dutyCycle = 0;
uint frequency = 3 * 1000;
try
{
modulator = new Meridian.PWM();
for (dutyCycle = 0; dutyCycle < 101; dutyCycle += 10)
{
modulator.Configure(frequency, dutyCycle);
//Update the text, in my intention
text.TextContent =
Resources.GetString(Resources.StringResources.Running1) + frequency +
Resources.GetString(Resources.StringResources.Running2) + dutyCycle;
Debug.Print(Resources.GetString(Resources.StringResources.Running1) +
frequency + Resources.GetString(Resources.StringResources.Running2) +
dutyCycle);
System.Threading.Thread.Sleep(1 * 1000);
}
}
catch (Exception)
{
text.TextContent =
Resources.GetString(Resources.StringResources.Exception) + dutyCycle;
}
}
OutputA is a method of an Application, MainWindow is the only window I have,
MainWindow.Child is a Panel, MainWindow.Child.Children[0] is a Text control
initialized to a string.
It goes through the 10 iterations and the text remains the same all the
time. Then, after the last one, it updates (but I obviously see only the last
string I wrote).
As I understand, the GUI is updated in another thread, but I am sleeping a
sec for each iteration: I guess this is enough for the scheduler to switch to
the GUI thread and let it update the screen, so what's wrong with my code?
Thanks in advance for the help!
Matteo