diff --git a/examples/Makefile b/examples/Makefile index c7b47a5..902478e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -25,6 +25,11 @@ test-ui.exe: PKGS = gtk-sharp-2.0 test-ui.exe: NDesk.DBus.dll NDesk.DBus.GLib.dll TestUI.cs +test-threads.exe: PKGS = gtk-sharp-2.0 + +test-threads.exe: NDesk.DBus.dll NDesk.DBus.GLib.dll TestThreads.cs + + run: echo '#!/bin/sh' > $@ echo 'export MONO_PATH=$(DBUS_SHARP_GLIB_PREFIX)/glib:$(DBUS_SHARP_PREFIX)/src:$$MONO_PATH' >> $@ diff --git a/examples/TestThreads.cs b/examples/TestThreads.cs new file mode 100644 index 0000000..dee621f --- /dev/null +++ b/examples/TestThreads.cs @@ -0,0 +1,68 @@ +// Copyright 2006 Alp Toker +// This software is made available under the MIT License +// See COPYING for details + +using System; +//using ST = System.Threading; +using System.Threading; +using Gtk; +using NDesk.DBus; +using org.freedesktop.DBus; + +public class TestThreads +{ + public static void OnClick (object o, EventArgs args) + { + foreach (string n in bus.ListNames ()) { + TextIter endIter = tv.Buffer.EndIter; + tv.Buffer.Insert (ref endIter, n + '\n'); + } + } + + public static void Task () + { + Console.WriteLine (bus.ListNames ()); + } + + public static void OnClickQuit (object o, EventArgs args) + { + //Application.Quit (); + Thread t = new Thread (Task); + t.Start (); + } + + static TextView tv; + + static IBus bus; + + public static void Main () + { + BusG.Init (); + Application.Init (); + + tv = new TextView (); + ScrolledWindow sw = new ScrolledWindow (); + sw.Add (tv); + + Button btn = new Button ("Click me"); + btn.Clicked += OnClick; + + Button btnq = new Button ("Click me (thread)"); + btnq.Clicked += OnClickQuit; + + VBox vb = new VBox (false, 2); + vb.PackStart (sw, true, true, 0); + vb.PackStart (btn, false, true, 0); + vb.PackStart (btnq, false, true, 0); + + Window win = new Window ("D-Bus#"); + win.SetDefaultSize (640, 480); + win.Add (vb); + win.Destroyed += delegate {Application.Quit ();}; + win.ShowAll (); + + bus = Bus.Session.GetObject ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus")); + + Application.Run (); + } +}