// [HandleProcessCorruptedStateExceptions] private static void mainThread() { try { _mainSignal = new AutoResetEvent(false); int timeout = Timeout.Infinite; DateTime lastEvents = DateTime.MinValue; _isRunning = true; _programSignal.Set(); // this signals to program thread that loop is running while (true) { if (_shutDown) { break; } _mainSignal.WaitOne(timeout, false); if (_shutDown) { break; } lock (SyncObject) { if (Session.SessionPtr != IntPtr.Zero) { do { libspotify.sp_session_process_events(Session.SessionPtr, out timeout); } while (!_shutDown && timeout == 0); } while (_mq.Count > 0) { MainThreadMessage m = _mq.Dequeue(); m.d.Invoke(m.payload); } } } } catch (Exception ex) { Spotify.Log.ErrorFormat("mainThread() unhandled exception: {0}", ex); } finally { _isRunning = false; if (_programSignal != null) { _programSignal.Set(); } } }
private static void mainThread() { try { _mainSignal = new AutoResetEvent(false); int timeout = Timeout.Infinite; DateTime lastEvents = DateTime.MinValue; _isRunning = true; _programSignal.Set(); // this signals to program thread that loop is running while (true) { if (_shutDown) { break; } _mainSignal.WaitOne(timeout, false); if (_shutDown) { break; } lock (_syncObj) { try { if (Session.GetSessionPtr() != IntPtr.Zero) { do { libspotify.sp_session_process_events(Session.GetSessionPtr(), out timeout); } while (timeout == 0); } } catch (Exception ex) { Logger.WriteDebug("libspotify> Exception invoking sp_session_process_events - {0}", ex.Message); } while (_mq.Count > 0) { MainThreadMessage m = _mq.Dequeue(); m.d.Invoke(m.payload); } } } } catch (Exception ex) { Logger.WriteDebug("libspotify> mainThread() unhandled exception: {0}", ex.ToString()); } finally { _isRunning = false; if (_programSignal != null) { _programSignal.Set(); } } }
private static void mainThread() { try { LogTo.Debug("Starting Spotify thread"); _mainSignal = new AutoResetEvent(false); int timeout = Timeout.Infinite; DateTime lastEvents = DateTime.MinValue; _isRunning = true; _programSignal.Set(); // this signals to program thread that loop is running while (true) { if (_shutDown) { break; } _mainSignal.WaitOne(timeout, false); if (_shutDown) { break; } lock (_syncObj) { try { if (Session.SessionPtr != IntPtr.Zero) { do { libspotify.sp_session_process_events(Session.SessionPtr, out timeout); } while (!_shutDown && timeout == 0); } } catch (Exception ex) { LogTo.Error("Exception invoking sp_session_process_events: {0} - {1}", ex.GetType().ToString(), ex.Message); LogTo.ErrorException("Exception was: ", ex); Log.Debug(Plugin.LOG_MODULE, "Exception invoking sp_session_process_events", ex); } while (_mq.Count > 0) { MainThreadMessage m = _mq.Dequeue(); m.d.Invoke(m.payload); } } } } catch (Exception ex) { LogTo.Fatal("Spotify mainthread() unhandled {0}: {1}", ex.GetType().ToString(), ex.Message); LogTo.FatalException("Exception was: ", ex); } finally { _isRunning = false; if (_programSignal != null) { _programSignal.Set(); } while (true) { LogTo.Fatal("Spotify thread is dead."); Thread.Sleep(1000); } // TODO Signal rest of application to shutdown } }