private async void btnConnect_Click(object sender, EventArgs e) { btnConnect.Enabled = false; Client = new CustomClient(GetUrl()); Application.ApplicationExit += Application_ApplicationExit; Client.RaiseLog += msg => WriteLog(msg); Client.Error += WriteError; Client.ConnectionStateChanged += ConnectionStateChanged; if (await Client.ConnectAsync()) { bool isValid = await Client.UsernameVerificationAsync(txtUsername.Value, txtPassword.Value, txtCategory.Value); ActiveControls(isValid); } }