Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15419 for trunk/sources


Ignore:
Timestamp:
10/13/17 14:21:09 (7 years ago)
Author:
pfleck
Message:

#2846: Fixed uncaught ObjectDisposedException in HiveJobManagerView.

  • Caught a potential NullReferenceException in the HiveClient when ClearHiveClient is called asynchronous.
  • Use Task.Run for HiveClient.Refresh instead of Begin/EndInvoke.
  • Use await with try-catch to marshal back any uncaught exceptions back to the UI-thread where the exception is displayed instead of HL crashing.
Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveJobManagerView.cs

    r14185 r15419  
    6161    }
    6262
    63     protected override void OnContentChanged() {
     63    protected async override void OnContentChanged() {
    6464      base.OnContentChanged();
    6565      if (Content == null) {
     
    6767      } else {
    6868        hiveExperimentListView.Content = Content.Jobs;
    69         if (Content != null)
    70           Content.RefreshAsync(new Action<Exception>((Exception ex) => HandleServiceException(ex)));
     69        if (Content != null) {
     70          try {
     71            await System.Threading.Tasks.Task.Run(() => Content.Refresh());
     72          } catch (Exception ex) {
     73            HandleServiceException(ex);
     74          }
     75        }
    7176      }
    7277    }
     
    98103    }
    99104
    100     private void refreshButton_Click(object sender, EventArgs e) {
    101       Content.RefreshAsync(new Action<Exception>((Exception ex) => HandleServiceException(ex)));
     105    private async void refreshButton_Click(object sender, EventArgs e) {
     106      try {
     107        await System.Threading.Tasks.Task.Run(() => Content.Refresh());
     108      } catch (Exception ex) {
     109        HandleServiceException(ex);
     110      }
    102111    }
    103112
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r14901 r15419  
    9999          jobs.Add(new RefreshableJob(j));
    100100        }
    101       }
    102       catch {
     101      } catch (NullReferenceException) {
     102        // jobs was set to null during ClearHiveClient
     103      } catch {
    103104        jobs = null;
    104105        throw;
    105       }
    106       finally {
     106      } finally {
    107107        OnRefreshed();
    108108      }
    109     }
    110 
    111     public void RefreshAsync(Action<Exception> exceptionCallback) {
    112       var call = new Func<Exception>(delegate() {
    113         try {
    114           Refresh();
    115         }
    116         catch (Exception ex) {
    117           return ex;
    118         }
    119         return null;
    120       });
    121       call.BeginInvoke(delegate(IAsyncResult result) {
    122         Exception ex = call.EndInvoke(result);
    123         if (ex != null) exceptionCallback(ex);
    124       }, null);
    125109    }
    126110    #endregion
     
    146130    }
    147131    public static void StoreAsync(Action<Exception> exceptionCallback, IHiveItem item, CancellationToken cancellationToken) {
    148       var call = new Func<Exception>(delegate() {
     132      var call = new Func<Exception>(delegate () {
    149133        try {
    150134          Store(item, cancellationToken);
    151         }
    152         catch (Exception ex) {
     135        } catch (Exception ex) {
    153136          return ex;
    154137        }
    155138        return null;
    156139      });
    157       call.BeginInvoke(delegate(IAsyncResult result) {
     140      call.BeginInvoke(delegate (IAsyncResult result) {
    158141        Exception ex = call.EndInvoke(result);
    159142        if (ex != null) exceptionCallback(ex);
     
    294277        }
    295278        TS.Task.WaitAll(tasks.ToArray());
    296       }
    297       finally {
     279      } finally {
    298280        refreshableJob.Job.Modified = false;
    299281        refreshableJob.IsProgressing = false;
     
    394376        taskUploadSemaphore.Release(); semaphoreReleased = true; // the semaphore has to be release before waitall!
    395377        TS.Task.WaitAll(tasks.ToArray());
    396       }
    397       finally {
     378      } finally {
    398379        if (!semaphoreReleased) taskUploadSemaphore.Release();
    399380      }
     
    443424        } else if (refreshableJob.IsPaused()) {
    444425          refreshableJob.ExecutionState = Core.ExecutionState.Paused;
    445         } else { 
     426        } else {
    446427          refreshableJob.ExecutionState = Core.ExecutionState.Started;
    447428        }
    448429        refreshableJob.OnLoaded();
    449       }
    450       finally {
     430      } finally {
    451431        refreshableJob.IsProgressing = false;
    452432        refreshableJob.Progress.Finish();
     
    485465      try {
    486466        return PersistenceUtil.Deserialize<ItemTask>(taskData.Data);
    487       }
    488       catch {
     467      } catch {
    489468        return null;
    490469      }
     
    497476    public static void TryAndRepeat(Action action, int repetitions, string errorMessage, ILog log = null) {
    498477      while (true) {
    499         try { action(); return; }
    500         catch (Exception e) {
     478        try { action(); return; } catch (Exception e) {
    501479          if (repetitions == 0) throw new HiveException(errorMessage, e);
    502480          if (log != null) log.LogMessage(string.Format("{0}: {1} - will try again!", errorMessage, e.ToString()));
Note: See TracChangeset for help on using the changeset viewer.