Skip to content

Commit

Permalink
Dispose of events
Browse files Browse the repository at this point in the history
  • Loading branch information
jimgraham committed Mar 29, 2012
1 parent 27032d2 commit 3e45f15
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions NetSparkle/NetSparkle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ public void StopLoop()
public void Dispose()
{
StopLoop();
UnregisterEvents();
}

/// <summary>
/// Unregisters events so that we don't have multiple items updating
/// </summary>
private void UnregisterEvents()
{
if ( this.ProgressWindow != null )
{
this.ProgressWindow.InstallAndRelaunch -= new EventHandler(OnProgressWindowInstallAndRelaunch);
}

if (_webDownloadClient != null)
{
_webDownloadClient.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(this.ProgressWindow.OnClientDownloadProgressChanged);
_webDownloadClient.DownloadFileCompleted -= new AsyncCompletedEventHandler(OnWebDownloadClientDownloadFileCompleted);
_webDownloadClient = null;
}
}

/// <summary>
Expand Down Expand Up @@ -499,11 +518,23 @@ private void InitDownloadAndInstallProcess(NetSparkleAppCastItem item)
{
this.ProgressWindow = new NetSparkleDownloadProgress(this, item, ApplicationIcon, ApplicationWindowIcon, EnableSilentMode);
}
else
{
this.ProgressWindow.InstallAndRelaunch -= new EventHandler(OnProgressWindowInstallAndRelaunch);
}

this.ProgressWindow.TempFileName = _downloadTempFileName;
this.ProgressWindow.InstallAndRelaunch += new EventHandler(OnProgressWindowInstallAndRelaunch);

// set up the download client
// start async download
if (_webDownloadClient != null)
{
_webDownloadClient.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(this.ProgressWindow.OnClientDownloadProgressChanged);
_webDownloadClient.DownloadFileCompleted -= new AsyncCompletedEventHandler(OnWebDownloadClientDownloadFileCompleted);
_webDownloadClient = null;
}

_webDownloadClient = new WebClient();
_webDownloadClient.UseDefaultCredentials = true;
_webDownloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.ProgressWindow.OnClientDownloadProgressChanged);
Expand Down

0 comments on commit 3e45f15

Please sign in to comment.