[Gtk-sharp-list] How to stop an Idle Thread

KLessou klessou at gmail.com
Tue Feb 27 13:01:40 EST 2007


Hello can we synchronize Glib.Idle Thread ?

For example here, if I press "Hello World" three times, I want to have a
result like this :

1 (first click)
2
3
(...)
49
1 (second click)
2
3
4
(...)
30
1 (third click)
2
3
(...)
100

If there is no solution for you, how do you make something like this ?

Thx


public class HelloWorld {
  public void hello (object obj, EventArgs args)
  {
     Console.WriteLine("Hello World");

     // How to stop the previous Thread here ?

     GLib.Idle.Add (new IdleHandler (OnIdleHello));
     OnIdleHello();
  }

  public void OnIdleHello (object obj, EventArgs args)
  {
     while (i <= 100)
     {
       Console.WriteLine(i);
       Thread.Sleep(3000);
     }
  }

  static void delete_event (object obj, DeleteEventArgs args)
  {
    Console.WriteLine ("delete event occurred\n");
    Application.Quit ();
  }

  public static void Main(string[] args)
  {
    Application.Init ();
    Window window = new Window ("helloworld");
    window.DeleteEvent += new DeleteEventHandler (delete_event);
    window.BorderWidth = 10;

    Button btn = new Button ("Hello World");

    btn.Clicked += new EventHandler (hello);

    window.Add (btn);

    window.ShowAll ();
    Application.Run ();
  }
}


-- 
~~~~~
| klessou |
~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20070227/966d9f9b/attachment.html 


More information about the Gtk-sharp-list mailing list