diff --git a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs index ca902a57..fd9d657c 100644 --- a/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs +++ b/LibationWinForms/BookLiberation/BaseForms/ProcessBaseForm.cs @@ -21,13 +21,13 @@ namespace LibationWinForms.BookLiberation processable.Completed += OnCompleted; processable.StatusUpdate += OnStatusUpdate; - //If IStreamable.StreamingCompleted is never fired, we still - //need to dispose of the form after IProcessable.Completed + //The form is created on IProcessable.Begin and we + //dispose of it on IProcessable.Completed processable.Completed += OnCompletedDispose; - //Don't unsubscribe from Dispose because it fires on - //IStreamable.StreamingCompleted, and the IProcessable - //events need to live past that event. + //Don't unsubscribe from Dispose because it fires when + //IStreamable.StreamingCompleted closes the form, and + //the IProcessable events need to live past that event. processable.Completed += OnUnsubscribeAll; } } diff --git a/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs b/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs index 13337e13..58860aea 100644 --- a/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs +++ b/LibationWinForms/BookLiberation/BaseForms/StreamBaseForm.cs @@ -34,12 +34,12 @@ namespace LibationWinForms.BookLiberation Streamable.StreamingProgressChanged += OnStreamingProgressChanged; Streamable.StreamingTimeRemaining += OnStreamingTimeRemaining; - Disposed += OnUnsubscribeAll; + FormClosed += OnUnsubscribeAll; } private void OnUnsubscribeAll(object sender, EventArgs e) { - Disposed -= OnUnsubscribeAll; + FormClosed -= OnUnsubscribeAll; Streamable.StreamingBegin -= OnStreamingBegin; Streamable.StreamingCompleted -= OnStreamingCompleted; @@ -55,30 +55,24 @@ namespace LibationWinForms.BookLiberation //thread that created form, otherwise the form and the window handle will be on //different threads. Form.BeginInvoke won't work until the form is created //(ie. shown) because control doesn't get a window handle until it is Shown. - static void sendCallback(object asyncArgs) { var e = asyncArgs as AsyncCompletedEventArgs; ((Action)e.UserState)(); } - Action code = Show; + Action show = Show; if (InvokeRequired) SyncContext.Send( sendCallback, - new AsyncCompletedEventArgs(null, false, code)); + new AsyncCompletedEventArgs(null, false, show)); else - code(); + show(); } public virtual void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { } public virtual void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) { } - public virtual void OnStreamingCompleted(object sender, string completedString) - => this.UIThread(() => - { - Close(); - Dispose(); - }); + public virtual void OnStreamingCompleted(object sender, string completedString) => this.UIThread(() => Close()); #endregion } }