mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 03:05:41 +00:00
Add sample, not in default build
svn path=/trunk/gtk-sharp/; revision=49380
This commit is contained in:
parent
95a22dd13b
commit
eb50593ba1
59
sample/Thread.cs
Normal file
59
sample/Thread.cs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
//
|
||||||
|
// Thread.cs - Using threads with Gtk#
|
||||||
|
//
|
||||||
|
// Author: Miguel de Icaza
|
||||||
|
//
|
||||||
|
// (c) 2005 Novell, Inc.
|
||||||
|
|
||||||
|
namespace GtkSamples {
|
||||||
|
|
||||||
|
using Gtk;
|
||||||
|
using Gdk;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
public class HelloThreads {
|
||||||
|
static Label msg;
|
||||||
|
static Button but;
|
||||||
|
static int count;
|
||||||
|
static Thread thr;
|
||||||
|
|
||||||
|
public static int Main (string[] args)
|
||||||
|
{
|
||||||
|
Application.Init ();
|
||||||
|
Gtk.Window win = new Gtk.Window ("Gtk# Hello World");
|
||||||
|
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
|
||||||
|
msg = new Label ("Click to quit");
|
||||||
|
but = new Button (msg);
|
||||||
|
but.Clicked += delegate { thr.Abort (); Application.Quit (); };
|
||||||
|
win.Add (but);
|
||||||
|
win.ShowAll ();
|
||||||
|
|
||||||
|
thr = new Thread (ThreadMethod);
|
||||||
|
thr.Start ();
|
||||||
|
|
||||||
|
Application.Run ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ThreadMethod ()
|
||||||
|
{
|
||||||
|
Console.WriteLine ("Starting thread");
|
||||||
|
while (true){
|
||||||
|
count++;
|
||||||
|
Thread.Sleep (500);
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
msg.Text = String.Format ("Click to Quit ({0})", count);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Window_Delete (object obj, DeleteEventArgs args)
|
||||||
|
{
|
||||||
|
Application.Quit ();
|
||||||
|
args.RetVal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue