예제 #1
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());
#if DEBUG
                    Log.Info("Debug build: " + Application.ProductVersion);
#else
                    Log.Info("Build: " + Application.ProductVersion);
#endif

                    //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();
            }
        }
예제 #2
0
        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());
                    Log.Info(OSInfo.OSInfo.GetLastInstalledWindowsUpdateTimestampAsString());
                    Log.Info("Windows Media Player: [{0}]", OSInfo.OSInfo.GetWMPVersion());

                    // 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("TV Service is being stopped");
            }
            catch (Exception ex)
            {
                if (_started)
                {
                    Log.Error("TV Service terminated unexpectedly: {0}", ex.ToString());
                }
                else
                {
                    Log.Error("TV Service failed to start: {0}", ex.ToString());
                }
            }
            finally
            {
                _started = true; // otherwise the onstop code will not complete.
                OnStop();
            }
        }