void connection_StateChange(object sender, StateChangeEventArgs e) { if (e.CurrentState == ConnectionState.Closed) { connection.StateChange -= connection_StateChange; connection = null; } }