From 83e50d1313a0d0ff6621981cad192072741fd970 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 12 Jul 2014 10:12:42 +0200 Subject: [PATCH 1/2] Not waiting for init task completition in windows service mode in order to avoid timeout on start --- MediaBrowser.ServerApplication/MainStartup.cs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 9e31fc800c..ffb6a9add1 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -224,23 +224,22 @@ namespace MediaBrowser.ServerApplication // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); - } - - var task = _appHost.Init(initProgress); - Task.WaitAll(task); - - task = _appHost.RunStartupTasks(); - Task.WaitAll(task); - - SystemEvents.SessionEnding += SystemEvents_SessionEnding; - SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; + } + + SystemEvents.SessionEnding += SystemEvents_SessionEnding; + SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; + + var task = _appHost.Init(initProgress); + task = task.ContinueWith(new Action(a => _appHost.RunStartupTasks())); if (runService) - { + { StartService(logManager); } else - { + { + Task.WaitAll(task); + HideSplashScreen(); ShowTrayIcon(); From b2550f6dd34bea58226aee4b1c4fa26104b5cda9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 12 Jul 2014 10:21:58 +0200 Subject: [PATCH 2/2] As session switch can't launch browser and sessionending does nothing in window service mode, moved the events handler to run only in interactive mode --- MediaBrowser.ServerApplication/MainStartup.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index ffb6a9add1..4c81716ed5 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -226,8 +226,6 @@ namespace MediaBrowser.ServerApplication ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); } - SystemEvents.SessionEnding += SystemEvents_SessionEnding; - SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; var task = _appHost.Init(initProgress); task = task.ContinueWith(new Action(a => _appHost.RunStartupTasks())); @@ -239,7 +237,10 @@ namespace MediaBrowser.ServerApplication else { Task.WaitAll(task); - + + SystemEvents.SessionEnding += SystemEvents_SessionEnding; + SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; + HideSplashScreen(); ShowTrayIcon();