瀏覽代碼

Not waiting for init task completition in windows service mode in order to avoid timeout on start

Michael 11 年之前
父節點
當前提交
83e50d1313
共有 1 個文件被更改,包括 11 次插入12 次删除
  1. 11 12
      MediaBrowser.ServerApplication/MainStartup.cs

+ 11 - 12
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<Task>(a => _appHost.RunStartupTasks()));
 
             if (runService)
-            {
+            {
                 StartService(logManager);
             }
             else
-            {
+            {
+                Task.WaitAll(task);
+                
                 HideSplashScreen();
 
                 ShowTrayIcon();