Пример #1
0
        public static Task <object> InvokeGtkThread(Func <object> func)
        {
            if (worker == null || !worker.IsBusy)
            {
                throw new Exception("DBusBackgroundWorker not running.");
            }
            var completionSource = new TaskCompletionSource <object>();

            taskList.Add(completionSource);
            Gtk.ReadyEvent readyEvent = () => {
                try {
                    completionSource.TrySetResult(func.Invoke());
                } catch (Exception ex) {
                    completionSource.TrySetException(ex);
                } finally {
                    taskList.Remove(completionSource);
                }
            };
            if (ReferenceEquals(Thread.CurrentThread, gtkThread))
            {
                readyEvent.Invoke();
            }
            else
            {
                var threadNotify = new Gtk.ThreadNotify(readyEvent);
                threadNotify.WakeupMain();
            }
            return(completionSource.Task);
        }
 public static void InvokeGtkThread(Action action)
 {
     if (mWorker == null || !mWorker.IsBusy)
     {
         throw new Exception("DBusBackgroundWorker not running.");
     }
     if (ReferenceEquals(Thread.CurrentThread, mGtkThread))
     {
         action.Invoke();
     }
     else
     {
         Gtk.ReadyEvent readyEvent   = () => action.Invoke();
         var            threadNotify = new Gtk.ThreadNotify(readyEvent);
         threadNotify.WakeupMain();
     }
 }