Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/17 11:14:27 (6 years ago)
Author:
pfleck
Message:

#2845:

  • Start progres with initial progress value in several cases to use the progress value update.
  • Removed object disposal guard in ProgressView because it can block part of the initialization.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r15415 r15446  
    6161      set {
    6262        if (InvokeRequired) {
    63           Action<string> action = delegate(string s) { this.Title = s; };
     63          Action<string> action = delegate (string s) { this.Title = s; };
    6464          Invoke(action, value);
    6565        } else
     
    7272      set {
    7373        if (InvokeRequired) {
    74           Action<Cursor> action = delegate(Cursor c) { this.Cursor = c; };
     74          Action<Cursor> action = delegate (Cursor c) { this.Cursor = c; };
    7575          Invoke(action, value);
    7676        } else
     
    9595        if (this.activeView != value) {
    9696          if (InvokeRequired) {
    97             Action<IView> action = delegate(IView activeView) { this.ActiveView = activeView; };
     97            Action<IView> action = delegate (IView activeView) { this.ActiveView = activeView; };
    9898            Invoke(action, value);
    9999          } else {
     
    230230    }
    231231
    232     public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class,IContent {
     232    public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class, IContent {
    233233      if (content == null) throw new ArgumentNullException("Content cannot be null.");
    234234      if (!reuseExistingView) return ShowContent(content);
     
    350350    private readonly List<ProgressView> progressViews = new List<ProgressView>();
    351351
     352    public IProgress AddOperationProgressToContent(IContent content, string progressMessage, double? initialProgressValue = null, bool addToObjectGraphObjects = true) {
     353      var progress = new Progress();
     354      if (initialProgressValue.HasValue)
     355        progress.Start(progressMessage, initialProgressValue.Value);
     356      else
     357        progress.Start(progressMessage);
     358      AddOperationProgressToContent(content, progress, addToObjectGraphObjects);
     359      return progress;
     360    }
    352361    /// <summary>
    353362    /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content.
    354363    /// </summary>
    355     [Obsolete]
    356     public IProgress AddOperationProgressToContent(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {
     364    public void AddOperationProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
    357365      if (InvokeRequired) {
    358         IProgress result = (IProgress)Invoke((Func<IContent, string, bool, IProgress>)AddOperationProgressToContent, content, progressMessage, addToObjectGraphObjects);
    359         return result;
     366        Invoke((Action<IContent, IProgress, bool>)AddOperationProgressToContent, content, progress, addToObjectGraphObjects);
     367        return;
    360368      }
    361369      if (contentProgressLookup.ContainsKey(content))
     
    372380        contentViews = contentViews.Where(v => v.Content == content);
    373381
    374       var progress = new Progress();
    375       progress.Start(progressMessage);
    376382      foreach (var contentView in contentViews) {
    377383        progressViews.Add(new ProgressView(contentView, progress));
     
    379385
    380386      contentProgressLookup[content] = progress;
     387    }
     388
     389    public IProgress AddOperationProgressToView(Control control, string progressMessage, double? initialProgressValue = null) {
     390      var progress = new Progress();
     391      if (initialProgressValue.HasValue)
     392        progress.Start(progressMessage, initialProgressValue.Value);
     393      else
     394        progress.Start(progressMessage);
     395      AddOperationProgressToView(control, progress);
    381396      return progress;
    382397    }
    383 
    384398    /// <summary>
    385399    /// Adds a <see cref="ProgressView"/> to the specified view.
    386400    /// </summary>
    387     [Obsolete]
    388     public IProgress AddOperationProgressToView(Control control, string progressMessage) {
    389       var progress = new Progress();
    390       progress.Start(progressMessage);
    391       AddOperationProgressToView(control, progress);
    392       return progress;
    393     }
    394 
    395401    public void AddOperationProgressToView(Control control, IProgress progress) {
    396402      if (InvokeRequired) {
     
    564570      try {
    565571        ((IActionUserInterfaceItem)item.Tag).Execute();
    566       }
    567       catch (Exception ex) {
     572      } catch (Exception ex) {
    568573        ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, ex);
    569574      }
Note: See TracChangeset for help on using the changeset viewer.