Guard against disconnect handler after window is closed