public MainForm() { // Check connection to database GeoViewerEntities context = null; try { context = new GeoViewerEntities(); var list = context.Accounts.Count(); } catch (Exception) { if (context != null) { context.Dispose(); } if (new SetupDatabase().ShowDialog() != DialogResult.OK) { Environment.Exit(0); } } // Check licence if (!LicenceBLL.ValidateKey()) { if (new AddLicenceForm().ShowDialog() != DialogResult.OK) { Environment.Exit(0); } } connectedToDatabase = true; MainApplicationForm = this; InitializeComponent(); // Check connection to database // Run background process ReaderThreadManager.Current.InitThreads(); ReaderThreadManager.Current.StartThreads(); }