private void Connection_StateChange(object sender, StateChangeEventArgs e) { if (e.CurrentState == ConnectionState.Open) { count++; if (count == 3) { EnterPasswordWindow pass = new EnterPasswordWindow(this); this.Invoke(new Action(() => { pass.Show(); })); } } else { MessageBox.Show("Connection state is ", "NOT OK" + e.CurrentState); } }