Ignore:
Timestamp:
01/16/13 11:13:18 (9 years ago)
Author:
ascheibe
Message:

#2005

  • renamed some events and methods
  • fixed some memory leaks
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs

    r9107 r9169  
    3131
    3232namespace HeuristicLab.Clients.Hive {
    33   public class RefreshableJob : IHiveItem, IDeepCloneable, IContent, IComparable<RefreshableJob> {
     33  public class RefreshableJob : IHiveItem, IDeepCloneable, IContent, IComparable<RefreshableJob>, IDisposable {
    3434    private JobResultPoller jobResultPoller;
    3535    private ConcurrentTaskDownloader<ItemTask> jobDownloader;
     
    4848            throw new ArgumentNullException();
    4949
    50           if (job != null) DergisterJobEvents();
     50          if (job != null) DeregisterJobEvents();
    5151          job = value;
    5252          if (job != null) {
     
    6666      set {
    6767        if (hiveTasks != value) {
    68           if (hiveTasks != null) DeregisterHiveJobsEvents();
     68          if (hiveTasks != null) DeregisterHiveTasksEvents();
    6969          hiveTasks = value;
    70           if (hiveTasks != null) RegisterHiveJobsEvents();
     70          if (hiveTasks != null) RegisterHiveTasksEvents();
    7171          OnHiveTasksChanged();
    7272        }
     
    240240      if (jobResultPoller != null && jobResultPoller.IsPolling) {
    241241        jobResultPoller.Stop();
     242        DeregisterResultPollingEvents();
    242243      }
    243244    }
     
    358359    }
    359360
    360     private void DergisterJobEvents() {
     361    private void DeregisterJobEvents() {
    361362      job.ToStringChanged -= new EventHandler(OnToStringChanged);
    362363      job.PropertyChanged -= new PropertyChangedEventHandler(job_PropertyChanged);
     
    473474
    474475    #region HiveTasks Events
    475     private void RegisterHiveJobsEvents() {
     476    private void RegisterHiveTasksEvents() {
    476477      this.hiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded);
    477478      this.hiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved);
     
    479480    }
    480481
    481     private void DeregisterHiveJobsEvents() {
     482    private void DeregisterHiveTasksEvents() {
    482483      this.hiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded);
    483484      this.hiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved);
     
    605606      return this.ToString().CompareTo(other.ToString());
    606607    }
     608
     609    #region IDisposable Members
     610    public void Dispose() {
     611      if (jobDownloader != null) {
     612        jobDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(jobDownloader_ExceptionOccured);
     613        jobDownloader.Dispose();
     614        jobDownloader = null;
     615      }
     616      if (job != null) {
     617        DeregisterJobEvents();
     618        job = null;
     619      }
     620      if (hiveTasks != null) {
     621        DeregisterHiveTasksEvents();
     622        hiveTasks.Clear(); // this should remove the item_StateLogChanged event handlers
     623        hiveTasks = null;
     624      }
     625      if (jobResultPoller != null) {
     626        DeregisterResultPollingEvents();
     627        jobResultPoller = null;
     628      }
     629    }
     630    #endregion
    607631  }
    608632}
Note: See TracChangeset for help on using the changeset viewer.