Index: branches/OaaS/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs
===================================================================
--- branches/OaaS/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs	(revision 8228)
+++ branches/OaaS/HeuristicLab.Clients.Hive/3.3/HiveTasks/HiveTask.cs	(revision 9363)
@@ -36,7 +36,8 @@
   [Item("Hive Task", "Represents a hive task.")]
   [StorableClass]
-  public class HiveTask : NamedItem, IItemTree<HiveTask> {
+  public class HiveTask : NamedItem, IItemTree<HiveTask>, IDisposable {
     protected static object locker = new object();
     protected ReaderWriterLockSlim childHiveTasksLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
+    protected ReaderWriterLockSlim itemTaskLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 
     public static new Image StaticItemImage {
@@ -66,7 +67,7 @@
       set {
         if (task != value) {
-          DeregisterJobEvents();
+          DeregisterTaskEvents();
           task = value;
-          RegisterJobEvents();
+          RegisterTaskEvents();
           IsFinishedTaskDownloaded = false;
           OnTaskChanged();
@@ -83,13 +84,22 @@
       set {
         if (itemTask != null && syncTasksWithOptimizers) {
-          this.childHiveTasks.Clear();
+          childHiveTasksLock.EnterWriteLock();
+          try {
+            childHiveTasks.Clear();
+          }
+          finally { childHiveTasksLock.ExitWriteLock(); }
         }
         if (itemTask != value) {
-          DergisterItemTaskEvents();
-          itemTask = value;
-          RegisterItemTaskEvents();
+          itemTaskLock.EnterWriteLock();
+          try {
+            DeregisterItemTaskEvents();
+            itemTask = value;
+            RegisterItemTaskEvents();
+          }
+          finally { itemTaskLock.ExitWriteLock(); }
           OnItemTaskChanged();
           IsFinishedTaskDownloaded = true;
         }
+
       }
     }
@@ -167,5 +177,5 @@
       this.childHiveTasks = new ItemList<HiveTask>();
       syncTasksWithOptimizers = true;
-      RegisterChildHiveJobEvents();
+      RegisterChildHiveTasksEvents();
     }
 
@@ -188,5 +198,5 @@
       this.childHiveTasks = new ItemList<HiveTask>();
       this.syncTasksWithOptimizers = true;
-      RegisterChildHiveJobEvents();
+      RegisterChildHiveTasksEvents();
     }
 
@@ -216,5 +226,5 @@
       }
     }
-    protected virtual void DergisterItemTaskEvents() {
+    protected virtual void DeregisterItemTaskEvents() {
       if (ItemTask != null) {
         ItemTask.ComputeInParallelChanged -= new EventHandler(ItemJob_ComputeInParallelChanged);
@@ -223,10 +233,10 @@
     }
 
-    protected virtual void RegisterChildHiveJobEvents() {
+    protected virtual void RegisterChildHiveTasksEvents() {
       this.childHiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsAdded);
       this.childHiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsRemoved);
       this.childHiveTasks.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnCollectionReset);
     }
-    protected virtual void DeregisterChildHiveJobEvents() {
+    protected virtual void DeregisterChildHiveTasksEvents() {
       this.childHiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsAdded);
       this.childHiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveTask>>(OnItemsRemoved);
@@ -332,15 +342,15 @@
     }
 
-    private void RegisterJobEvents() {
+    private void RegisterTaskEvents() {
       if (task != null)
-        task.PropertyChanged += new PropertyChangedEventHandler(job_PropertyChanged);
-    }
-
-    private void DeregisterJobEvents() {
+        task.PropertyChanged += new PropertyChangedEventHandler(task_PropertyChanged);
+    }
+
+    private void DeregisterTaskEvents() {
       if (task != null)
-        task.PropertyChanged += new PropertyChangedEventHandler(job_PropertyChanged);
-    }
-
-    private void job_PropertyChanged(object sender, PropertyChangedEventArgs e) {
+        task.PropertyChanged += new PropertyChangedEventHandler(task_PropertyChanged);
+    }
+
+    private void task_PropertyChanged(object sender, PropertyChangedEventArgs e) {
       if (e.PropertyName == "State") {
         IsFinishedTaskDownloaded = false;
@@ -516,4 +526,13 @@
       this.ItemTask.Item = null;
     }
+
+    public void Dispose() {
+      DeregisterChildHiveTasksEvents();
+      DeregisterTaskEvents();
+      DeregisterItemTaskEvents();
+      childHiveTasksLock.Dispose();
+      itemTaskLock.Dispose();
+      ClearData();
+    }
   }
 
