Beispiel #1
0
        static void backgroundDispatcher()
        {
            while (true)
            {
                GenericMessageContainer msg = null;
                bool wait = false;
                lock (backgroundQueue) {
                    if (backgroundQueue.Count == 0)
                    {
                        backgroundThreadWait.Reset();
                        wait = true;
                    }
                    else
                    {
                        msg = backgroundQueue.Dequeue();
                    }
                }

                if (wait)
                {
                    WaitHandle.WaitAll(new WaitHandle[] { backgroundThreadWait });
                    continue;
                }

                if (msg != null)
                {
                    msg.Run();
                    if (msg.Exception != null)
                    {
                        HandlerError(msg);
                    }
                }
            }
        }
Beispiel #2
0
        public static void ThreadDispatch(MessageHandler cb)
        {
            GenericMessageContainer smc = new GenericMessageContainer(cb, false);
            Thread t = new Thread(new ThreadStart(smc.Run));

            t.Name         = "Message dispatcher";
            t.IsBackground = true;
            t.Start();
        }
Beispiel #3
0
 static void QueueBackground(GenericMessageContainer c)
 {
     lock (backgroundQueue) {
         backgroundQueue.Enqueue(c);
         if (backgroundQueue.Count == 1)
         {
             backgroundThreadWait.Set();
         }
     }
 }
Beispiel #4
0
 static void QueueMessage(GenericMessageContainer msg)
 {
     lock (guiQueue) {
         guiQueue.Enqueue(msg);
         if (iIdle == 0)
         {
             iIdle = GLib.Timeout.Add(0, handler);
         }
     }
 }
Beispiel #5
0
 static void HandlerError(GenericMessageContainer msg)
 {
     if (msg.CallerStack != null)
     {
         LoggingService.LogError("{0} {1}\nCaller stack:{2}", errormsg, msg.Exception.ToString(), msg.CallerStack);
     }
     else
     {
         LoggingService.LogError("{0} {1}\nCaller stack not available. Define the environment variable MONODEVELOP_DISPATCH_DEBUG to enable caller stack capture.", errormsg, msg.Exception.ToString());
     }
 }
Beispiel #6
0
        public static void GuiSyncDispatch(MessageHandler cb)
        {
            if (IsGuiThread)
            {
                cb();
                return;
            }

            GenericMessageContainer mc = new GenericMessageContainer(cb, true);

            lock (mc) {
                QueueMessage(mc);
                Monitor.Wait(mc);
            }
            if (mc.Exception != null)
            {
                throw new Exception(errormsg, mc.Exception);
            }
        }
		static void HandlerError (GenericMessageContainer msg)
		{
			if (msg.CallerStack != null) {
				LoggingService.LogError ("{0} {1}\nCaller stack:{2}", errormsg, msg.Exception.ToString (), msg.CallerStack);
			}
			else
				LoggingService.LogError ("{0} {1}\nCaller stack not available. Define the environment variable MONODEVELOP_DISPATCH_DEBUG to enable caller stack capture.", errormsg, msg.Exception.ToString ());
		}
		static void QueueBackground (GenericMessageContainer c)
		{
			lock (backgroundQueue) {
				backgroundQueue.Enqueue (c);
				if (backgroundQueue.Count == 1)
					backgroundThreadWait.Set ();
			}
		}
		static void QueueMessage (GenericMessageContainer msg)
		{
			lock (guiQueue) {
				guiQueue.Enqueue (msg);
				if (iIdle == 0)
					iIdle = GLib.Timeout.Add (0, handler);
			}
		}
		static void GuiSyncDispatch (MessageHandler cb)
		{
			if (IsGuiThread) {
				cb ();
				return;
			}

			GenericMessageContainer mc = new GenericMessageContainer (cb, true);
			lock (mc) {
				QueueMessage (mc);
				Monitor.Wait (mc);
			}
			if (mc.Exception != null)
				throw new Exception (errormsg, mc.Exception);
		}