private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (ownerClosing) { return; } e.Cancel = false; if (!ended && conformCancel()) { closing = true; //Hide(); if (client.IsChild) { await client.DisconnectAsync(false, false); } else { client.OnConnecting -= Connecting; client.OnConnected -= Connected; client.OnFailedToConnect -= FailedToConnected; client.IsCanceled = true; client.Paused = false; await client.Abort(); } while (!ended) { await Task.Delay(100); } } e.Cancel = !ended && !closing; if (ended) { if (!shrink.Shrinked) { AppSettings.Set("TransferWindow", "Width", ActualWidth); this.SaveTopLeft("TransferWindow"); } ClientHelper.Owner.Closing -= OwnerClosing; ClientHelper.Owner.Activate(); } }