public void OnStart()
    {
      //System.Diagnostics.Debugger.Launch();
      try
      {
        if (!Started)
        {
          Log.Info("TV service: Starting");

          Thread.CurrentThread.Name = "TVService";

          // Log TvService start and versions
          FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
          Log.WriteFile("TVService v" + versionInfo.FileVersion + " is starting up on " +
            OSInfo.OSInfo.GetOSDisplayVersion());

          // Warn about unsupported operating systems
          OSPrerequisites.OSPrerequisites.OsCheck(false);

          // Start the power event thread
          _powerEventThread = new Thread(PowerEventThread);
          _powerEventThread.Name = "PowerEventThread";
          _powerEventThread.IsBackground = true;
          _powerEventThread.Start();

          // Init the TvController and start remoting
          _controller = new TVController();
          _controller.Init();
          StartRemoting();

          // Start the plugins
          StartPlugins();

          // Set "Global\MPTVServiceInitializedEvent"
          if (_InitializedEvent != null)
          {
            _InitializedEvent.Set();
          }
          _started = true;
          Log.Info("TV service: Started");

          // Wait for termination
          while (true)
          {
            Thread.Sleep(1000);
          }
        }
      }
      catch (ThreadAbortException)
      {
        Log.Info("TvService is being stopped");
      }
      catch (Exception ex)
      {
        if (_started)
          Log.Error("TvService terminated unexpectedly: {0}", ex.ToString());
        else
          Log.Error("TvService failed to start: {0}", ex.ToString());
      }
      finally
      {
        _started = true; // otherwise the onstop code will not complete.
        OnStop();
      }
    }
Exemple #2
0
    public void OnStart()
    {
      //System.Diagnostics.Debugger.Launch();
      try
      {
        if (!Started)
        {
          Log.Info("TV service: Starting");

          Thread.CurrentThread.Name = "TVService";

          FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);

          Log.WriteFile("TVService v" + versionInfo.FileVersion + " is starting up on " +
                        OSInfo.OSInfo.GetOSDisplayVersion());

          //Check for unsupported operating systems
          OSPrerequisites.OSPrerequisites.OsCheck(false);

          _powerEventThread = new Thread(PowerEventThread);
          _powerEventThread.Name = "PowerEventThread";
          _powerEventThread.IsBackground = true;
          _powerEventThread.Start();
          _controller = new TVController();
          _controller.Init();
          StartPlugins();

          StartRemoting();
          _started = true;
          if (_InitializedEvent != null)
          {
            _InitializedEvent.Set();
          }
          Log.Info("TV service: Started");
          while (true)
          {
            Thread.Sleep(1000);
          }
        }
      }
      catch (Exception ex)
      {
        //wait for thread to exit. eg. when stopping tvservice       
        Log.Error("TvService OnStart failed : {0}", ex.ToString());
        _started = true; // otherwise the onstop code will not complete.
        OnStop();
      }
    }