Ejemplo n.º 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();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts a new thread which scans the music library and stores the mirage
        /// data in the database.
        /// </summary>
        /// <param name="start">
        /// If start is true, the scan will be started. If it is false, the scan
        /// will be stopped. If start is true and the library is already being
        /// scanned, or if start is false and the library is not being scanned
        /// then this method does nothing.
        /// </param>
        public void Scan (bool start)
        {
            if (start == analyzing_lib)
                return;

            if (start) {
                if (CheckLibScanned ()) {
                    Finished ();
                    return;
                }
                lock (scan_synch) {
                    analyzing_lib = true;
                    stop_scan = false;
                }
                thr = new Thread (new ThreadStart (ScanMusicLibrary));
                finished = new Gtk.ThreadNotify (new Gtk.ReadyEvent (Finished));
                thr.Start();
            } else {
                lock (scan_synch) {
                    stop_scan = true;
                }
            }
            Hyena.Log.InformationFormat ("NoNoise/BLA - Scan {0}", (start ? "started." : "paused."));
        }
Ejemplo n.º 4
0
            public void ButtonPushHandler(object obj, EventArgs args)
            {
                Hyena.Log.Debug("NoNoise - Button pressed");

                Thread thr = new Thread (new ThreadStart(ThreadRoutine));
                thr.Start();
                ready = new Gtk.ThreadNotify (new Gtk.ReadyEvent(Ready));

                w.Remove(bw);
                w.Add(working);
                w.ShowAll();
                Hyena.Log.Debug("NoNoise - busy...");
            }