private async Task GenerateAsync() { if (!ValidateForm()) { return; } _generator = new ScriptGenerator(txtServerName.Text, txtDatabaseName.Text, txtUsername.Text, txtPassword.Text, rdbIntegrated.Checked, txtDirectory.Text); System.Timers.Timer timer = new System.Timers.Timer(1000); timer.Elapsed += timer_Elapsed; timer.AutoReset = true; try { Task gen = _generator.GenerateAsync(); timer.Enabled = true; await gen; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error connecting to database"); } finally { timer.Enabled = false; timer_Elapsed(); } }