Fixed event handling.
This commit is contained in:
parent
7acaac7bd3
commit
5ab4183f9b
@ -21,13 +21,13 @@ namespace LibationWinForms.BookLiberation
|
|||||||
processable.Completed += OnCompleted;
|
processable.Completed += OnCompleted;
|
||||||
processable.StatusUpdate += OnStatusUpdate;
|
processable.StatusUpdate += OnStatusUpdate;
|
||||||
|
|
||||||
//If IStreamable.StreamingCompleted is never fired, we still
|
//The form is created on IProcessable.Begin and we
|
||||||
//need to dispose of the form after IProcessable.Completed
|
//dispose of it on IProcessable.Completed
|
||||||
processable.Completed += OnCompletedDispose;
|
processable.Completed += OnCompletedDispose;
|
||||||
|
|
||||||
//Don't unsubscribe from Dispose because it fires on
|
//Don't unsubscribe from Dispose because it fires when
|
||||||
//IStreamable.StreamingCompleted, and the IProcessable
|
//IStreamable.StreamingCompleted closes the form, and
|
||||||
//events need to live past that event.
|
//the IProcessable events need to live past that event.
|
||||||
processable.Completed += OnUnsubscribeAll;
|
processable.Completed += OnUnsubscribeAll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,12 +34,12 @@ namespace LibationWinForms.BookLiberation
|
|||||||
Streamable.StreamingProgressChanged += OnStreamingProgressChanged;
|
Streamable.StreamingProgressChanged += OnStreamingProgressChanged;
|
||||||
Streamable.StreamingTimeRemaining += OnStreamingTimeRemaining;
|
Streamable.StreamingTimeRemaining += OnStreamingTimeRemaining;
|
||||||
|
|
||||||
Disposed += OnUnsubscribeAll;
|
FormClosed += OnUnsubscribeAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUnsubscribeAll(object sender, EventArgs e)
|
private void OnUnsubscribeAll(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Disposed -= OnUnsubscribeAll;
|
FormClosed -= OnUnsubscribeAll;
|
||||||
|
|
||||||
Streamable.StreamingBegin -= OnStreamingBegin;
|
Streamable.StreamingBegin -= OnStreamingBegin;
|
||||||
Streamable.StreamingCompleted -= OnStreamingCompleted;
|
Streamable.StreamingCompleted -= OnStreamingCompleted;
|
||||||
@ -55,30 +55,24 @@ namespace LibationWinForms.BookLiberation
|
|||||||
//thread that created form, otherwise the form and the window handle will be on
|
//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
|
//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.
|
//(ie. shown) because control doesn't get a window handle until it is Shown.
|
||||||
|
|
||||||
static void sendCallback(object asyncArgs)
|
static void sendCallback(object asyncArgs)
|
||||||
{
|
{
|
||||||
var e = asyncArgs as AsyncCompletedEventArgs;
|
var e = asyncArgs as AsyncCompletedEventArgs;
|
||||||
((Action)e.UserState)();
|
((Action)e.UserState)();
|
||||||
}
|
}
|
||||||
|
|
||||||
Action code = Show;
|
Action show = Show;
|
||||||
|
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
SyncContext.Send(
|
SyncContext.Send(
|
||||||
sendCallback,
|
sendCallback,
|
||||||
new AsyncCompletedEventArgs(null, false, code));
|
new AsyncCompletedEventArgs(null, false, show));
|
||||||
else
|
else
|
||||||
code();
|
show();
|
||||||
}
|
}
|
||||||
public virtual void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { }
|
public virtual void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { }
|
||||||
public virtual void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) { }
|
public virtual void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) { }
|
||||||
public virtual void OnStreamingCompleted(object sender, string completedString)
|
public virtual void OnStreamingCompleted(object sender, string completedString) => this.UIThread(() => Close());
|
||||||
=> this.UIThread(() =>
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
Dispose();
|
|
||||||
});
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user