[Mono-dev] timer locks up interface..
Giovanni A. D.
virtualdarkness at gmail.com
Thu Jan 12 17:34:01 EST 2006
hi,
I'm a beginner with mono and yesterday I tried to do a simple hello
world like app. using monodevelop and creating a glade 2 project
(glade-project-2.0.dtd).
I'm using mono 1.1.13 installed with the installer.
I've been able to set up a timer and the console output is exactly
what I'd expect; the problem cames when I try to output the value of
timecnt into a label..
it displays correctly the first 2 times then the interface freeze and
doesn't get update while the console output goes on fine.
any tip/idea? here is the code I wrote:
------------------------------------------------------------------------------------------------------------------------
using System;
using Gtk;
using Glade;
public class GladeApp
{
public static void Main (string[] args)
{
new GladeApp (args);
}
public GladeApp (string[] args)
{
Application.Init ();
Glade.XML gxml = new Glade.XML (null, "gui.glade", "window1", null);
gxml.Autoconnect (this);
button1.Clicked += OnClickButton1;
button2.Clicked += OnClickButton2;
startTimer();
Application.Run ();
}
System.Timers.Timer my_timer = new System.Timers.Timer(1000);
Int32 timecnt;
[Glade.Widget]
Button button1;
[Glade.Widget]
Button button2;
[Glade.Widget]
Label label1;
// Connect the Signals defined in Glade
private void OnWindowDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
private void OnClickButton1 (object o, EventArgs e)
{
Console.WriteLine("Start");
my_timer.Start();
}
private void OnClickButton2 (object o, EventArgs e)
{
Console.WriteLine("Stop");
my_timer.Stop();
}
private void doTimerClick(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("- timer - "+timecnt.ToString());
label1.Text=timecnt.ToString();
timecnt++;
if (timecnt > 10) {
timecnt=1;
}
}
private void startTimer() {
timecnt=1;
my_timer.Enabled = true;
my_timer.Elapsed += new System.Timers.ElapsedEventHandler(doTimerClick);
Console.WriteLine("Timer setup OK");
}
}
------------------------------------------------------------------------------------------------------------------------
thanks in advice for any reply.
bye,
Giovanni.
More information about the Mono-devel-list
mailing list