public static void InitializeTheSystem()
{
Verify.That(!_preInitHandlersRunning, "DataFacade related methods should not be called in OnBeforeInitialize() method of a startup handler. Please move the code to OnInitialized() instead.");
// if (AppDomain.CurrentDomain.Id == 3) SimpleDebug.AddEntry(string.Format("INITIALIZING {0} {1} {2}", Thread.CurrentThread.ManagedThreadId, _initializing, _coreInitialized));
if (_exceptionThrownDuringInitialization != null)
{
TimeSpan timeSpan = DateTime.Now - _exceptionThrownDuringInitializationTimeStamp;
if (timeSpan < TimeSpan.FromMinutes(5.0))
{
Log.LogCritical(LogTitleNormal, "Exception recorded:" + timeSpan + " ago");
throw new Exception("Failed to initialize the system", _exceptionThrownDuringInitialization);
}
_exceptionThrownDuringInitialization = null;
}
if (!_initializing && !_coreInitialized)
{
using (GlobalInitializerFacade.CoreLockScope)
{
if (!_initializing && !_coreInitialized)
{
try
{
_initializing = true;
if (!SystemSetupFacade.IsSystemFirstTimeInitialized && RuntimeInformation.IsDebugBuild)
{
Log.LogWarning(LogTitleNormal, new InvalidOperationException("System is initializing, yet missing first time initialization"));
}
using (ThreadDataManager.EnsureInitialize())
{
DoInitialize();
}
GC.Collect(); // Collecting generation 2 after initialization
_fatalErrorFlushCount = 0;
}
catch (Exception ex)
{
_exceptionThrownDuringInitialization = ex;
_exceptionThrownDuringInitializationTimeStamp = DateTime.Now;
var shutdownReason = HostingEnvironment.ShutdownReason;
if (shutdownReason != ApplicationShutdownReason.None)
{
Log.LogCritical(LogTitleNormal, "Shutdown reason: " + HostingEnvironment.ShutdownReason);
}
Log.LogCritical(LogTitleNormal, ex);
throw;
}
finally
{
_coreInitialized = true;
_initializing = false;
}
}
EnabledUnhandledExceptionsLogging();
}
}
}