// When the SongAlert closes set it to null in this scope so we know private void Song_Alert_Close(object sender, FormClosingEventArgs e) { // We must handle an unsafe thread disposal here so that the parent forms Dispose method does not cause cross thread errors // But first we have to check if the handle is created yet, if it isn't we attach to the HandleCreated event if (alert.IsHandleCreated) { Control.CheckForIllegalCrossThreadCalls = false; alert.Dispose(); Control.CheckForIllegalCrossThreadCalls = true; alert = null; } else { alert.HandleCreated += (send, ev) => { Control.CheckForIllegalCrossThreadCalls = false; alert.Dispose(); Control.CheckForIllegalCrossThreadCalls = true; alert = null; }; } }