Advertisement
Guest User

Mac OSX Thread issue

a guest
Jul 30th, 2010
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Gtk;
  4. using System.Drawing;
  5.  
  6. namespace MacGtkTest
  7. {
  8.     static class Program
  9.     {
  10.         [STAThread]
  11.         static void Main(string[] args)
  12.         {
  13.             if (args.Length != 1 || (args[0] != "W" && args[0] != "G"))
  14.             {
  15.                 Console.WriteLine("Usage: MacGtkTest W|G");
  16.                 return;
  17.             }
  18.  
  19.             if (args[0] == "W")
  20.             {
  21.                 System.Threading.Thread t = new System.Threading.Thread(RunGtkLoop);
  22.                 t.Start();
  23.  
  24.                 System.Threading.Thread.Sleep(5 * 1000);
  25.  
  26.                 RunWinLoop();
  27.             }
  28.             else
  29.             {
  30.                 System.Threading.Thread t = new System.Threading.Thread(RunWinLoop);
  31.                 t.Start();
  32.  
  33.                 System.Threading.Thread.Sleep(5 * 1000);
  34.  
  35.                 RunGtkLoop();
  36.             }
  37.         }
  38.  
  39.         static void RunWinLoop()
  40.         {
  41.             Console.WriteLine("Initializing WinForms");
  42.  
  43.             System.Windows.Forms.Application.EnableVisualStyles();
  44.             System.Windows.Forms.Application.DoEvents();
  45.  
  46.             Console.WriteLine("Running WinForms");
  47.  
  48.             System.Windows.Forms.Application.Run();
  49.  
  50.             Console.WriteLine("Exiting WinForms");
  51.         }
  52.  
  53.         static void RunGtkLoop()
  54.         {
  55.             Gtk.Application.Init();
  56.  
  57.             StatusIcon icon = new StatusIcon();
  58.             icon.Visible = false;
  59.  
  60.             Console.WriteLine("Initializing GTK icon");
  61.  
  62.             using (Bitmap bmp = new Bitmap(16, 16))
  63.             {
  64.                 using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
  65.                 {
  66.                     g.Clear(Color.Purple);
  67.                 }
  68.  
  69.                 using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  70.                 {
  71.                     bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  72.                     ms.Position = 0;
  73.  
  74.                     icon.Pixbuf = new Gdk.Pixbuf(ms);
  75.                 }
  76.             }
  77.  
  78.             Console.WriteLine("Setting GTK event handlers");
  79.  
  80.             icon.PopupMenu += new PopupMenuHandler(icon_PopupMenu);
  81.             icon.Activate += new EventHandler(icon_Activate);
  82.  
  83.             Console.WriteLine("Setting GTK icon visible");
  84.  
  85.             icon.Visible = true;
  86.  
  87.             Console.WriteLine("Starting GTK");
  88.  
  89.             Gtk.Application.Run();
  90.  
  91.             Console.WriteLine("Exiting GTK");
  92.         }
  93.  
  94.         static void icon_Activate(object sender, EventArgs e)
  95.         {
  96.             Console.WriteLine("Activate");
  97.         }
  98.  
  99.         static void icon_PopupMenu(object o, PopupMenuArgs args)
  100.         {
  101.             Console.WriteLine("Popup menu");
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement