private async void LoadingForm_Load(object sender, EventArgs e) { /* * Used Task.Run(..) here because here is the first call to DB with context (create connection, etg.) * and it will take much time and will lock main UI thread, even though the call is asynchronous */ var result = await Task.Run(async() => await _healthCheckService.IsApplicationAvailable()); if (!result) { throw new Exception("Ошибка инициализации базы данных"); } Context.SetExecutableForm(DIContainer.Resolve <LoginForm>()); Context.ShowExecutableForm(); Close(); }
static void Main() { Application.EnableVisualStyles(); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); Application.SetCompatibleTextRenderingDefault(false); using (DIContainer.Scope = ContainerConfig.Configure().BeginLifetimeScope()) { var logger = DIContainer.Resolve <ILogger>(); try { Context.SetExecutableForm(DIContainer.Resolve <LoadingForm>()); Application.Run(Context.MainContext); } catch (Exception ex) { MessageBox.Show($"В приложении произошла ошибка.\nПожалуйста предоставьте файл логгирования ({Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs")}) разработчикам.", "Ошибка выполнения", MessageBoxButtons.OK, MessageBoxIcon.Error); logger.LogError(ex); } } }