Index: trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs
===================================================================
--- trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs	(revision 2067)
+++ trunk/sources/HeuristicLab.Hive.Client.Communication/3.2/WcfService.cs	(revision 2068)
@@ -278,13 +278,4 @@
     /// Send back finished and Stored Job Results
     /// </summary>
-    /*#region SendJobResults
-    public event System.EventHandler<StoreFinishedJobResultCompletedEventArgs> ProcessStoredJobResultCompleted;
-    public void ProcessStoredJobResultAsync(Guid clientId, long jobId, byte[] result, double percentage, Exception exception, bool finished) {
-      if (ConnState == NetworkEnum.WcfConnState.Loggedin)
-        //TODO: some sort of algo for the stored jobs
-        proxy.ProcessJobResultAsync(clientId, jobId, result, percentage, exception, finished);
-    }  
-    #endregion  */
-
     private Stream GetStreamedJobResult(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
       JobResult jobResult =
Index: trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
===================================================================
--- trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs	(revision 2067)
+++ trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs	(revision 2068)
@@ -173,5 +173,6 @@
           break;     
         
-        
+
+        //When the timeslice is up
         case MessageContainer.MessageType.UptimeLimitDisconnect:
           Logging.Instance.Info(this.ToString(), "Uptime Limit reached, storing jobs and sending them back");
@@ -211,4 +212,9 @@
     #region Async Threads for the EE
     
+    /// <summary>
+    /// serializes the finished job and submits it to the server. If, at the time, a network connection is unavailable, the Job gets stored on the disk. 
+    /// once the connection gets reestablished, the job gets submitted
+    /// </summary>
+    /// <param name="jobId"></param>
     private void GetFinishedJob(object jobId) {
       Guid jId = (Guid)jobId;      
@@ -255,13 +261,5 @@
       //Uptime Limit reached, now is a good time to destroy this jobs.
       if (!UptimeManager.Instance.isOnline()) {
-        lock (engines) {
-          appDomains[jId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
-          AppDomain.Unload(appDomains[jId]);
-          appDomains.Remove(jId);
-          engines.Remove(jId);
-          jobs.Remove(jId);
-        }
-        GC.Collect();
-
+        KillAppDomain(jId);        
         //Still anything running?
         if (engines.Count == 0)
@@ -277,5 +275,9 @@
     //Eventhandlers for the communication with the wcf Layer 
     #region wcfService Events
-
+    /// <summary>
+    /// Login has returned
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_LoginCompleted(object sender, LoginCompletedEventArgs e) {
       if (e.Result.Success) {
@@ -286,10 +288,12 @@
     }    
 
+    /// <summary>
+    /// A new Job from the wcfService has been received and will be started within a AppDomain.
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) {
       if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) {        
         bool sandboxed = false;
-        //todo: For testing!!!
-        //beat.StopHeartBeat();        
-        //Todo: make a set & override the equals method
         List<byte[]> files = new List<byte[]>();
         foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded))
@@ -318,23 +322,12 @@
     }
 
+    /// <summary>
+    /// A finished job has been stored on the server
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) {
-      lock(engines) {
-        try {
-          appDomains[e.Result.JobId].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
-          AppDomain.Unload(appDomains[e.Result.JobId]);
-          appDomains.Remove(e.Result.JobId);
-          engines.Remove(e.Result.JobId);
-          jobs.Remove(e.Result.JobId);
-        }
-        catch (Exception ex) {
-          Logging.Instance.Error(this.ToString(), "Exception when unloading the appdomain: ", ex);
-        }
-      }
-      if (e.Result.Success) {        
-      
-        //if the engine is running again -> we sent an snapshot. Otherwise the job was finished
-        //this method has a risk concerning race conditions.
-        //better expand the sendjobresultcompltedeventargs with a boolean "snapshot?" flag
-
+      KillAppDomain(e.Result.JobId);
+      if (e.Result.Success) {            
         ClientStatusInfo.JobsProcessed++;
         Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);                
@@ -344,24 +337,41 @@
     }
 
+    /// <summary>
+    /// A snapshot has been stored on the server
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_ProcessSnapshotCompleted(object sender, ProcessSnapshotCompletedEventArgs e) {
       Logging.Instance.Info(this.ToString(), "Snapshot " + e.Result.JobId + " has been transmitted according to plan.");
     }
 
-    //Todo: First stop all threads, then terminate
+    /// <summary>
+    /// The server has been changed. All Appdomains and Jobs must be aborted!
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_ServerChanged(object sender, EventArgs e) {
       Logging.Instance.Info(this.ToString(), "ServerChanged has been called");
       lock (engines) {
-        foreach (KeyValuePair<Guid, AppDomain> entries in appDomains) {
-          appDomains[entries.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
-          AppDomain.Unload(appDomains[entries.Key]);
+        foreach (KeyValuePair<Guid, Executor> entries in engines) {
+          engines[entries.Key].Abort();
+          //appDomains[entries.Key].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
+          //AppDomain.Unload(appDomains[entries.Key]);
         }
-        appDomains = new Dictionary<Guid, AppDomain>();
-        engines = new Dictionary<Guid, Executor>();
-      }
-    }
-
+        //appDomains = new Dictionary<Guid, AppDomain>();
+        //engines = new Dictionary<Guid, Executor>();
+        //jobs = new Dictionary<Guid, Job>();
+      }
+    }
+
+    /// <summary>
+    /// Connnection to the server has been estabilshed => Login and Send the persistet Jobs from the harddisk.
+    /// </summary>
+    /// <param name="sender"></param>
+    /// <param name="e"></param>
     void wcfService_Connected(object sender, EventArgs e) {
-      wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());
+      wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());      
       JobStorageManager.CheckAndSubmitJobsFromDisc();
+      currentlyFetching = false;
     }
 
@@ -392,4 +402,24 @@
       return jobs;
     }
+
+    /// <summary>
+    /// Kill a appdomain with a specific id.
+    /// </summary>
+    /// <param name="id">the GUID of the job</param>
+    private void KillAppDomain(Guid id) {
+      lock (engines) {
+        try {
+          appDomains[id].UnhandledException -= new UnhandledExceptionEventHandler(appDomain_UnhandledException);
+          AppDomain.Unload(appDomains[id]);
+          appDomains.Remove(id);
+          engines.Remove(id);
+          jobs.Remove(id);
+        }        
+        catch (Exception ex) {
+          Logging.Instance.Error(this.ToString(), "Exception when unloading the appdomain: ", ex);
+        }
+      }
+      GC.Collect();
+    }
   }
 }
