Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/29/12 23:12:32 (12 years ago)
Author:
abeham
Message:

#1762: Some changes to progress handling, see the ticket for more details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

    r8160 r8165  
    3939    public new IOptimizer Content {
    4040      get { return (IOptimizer)base.Content; }
    41       set {
    42         base.Content = value;
    43       }
     41      set { base.Content = value; }
    4442    }
    4543
     
    5654    Algorithm selectedAlgorithm = null;
    5755    Problem selectedProblem = null;
    58     private ProgressView progressView;
    59     private IProgress progress;
     56    private ProgressView progressView; // this has to be disposed manually!
     57    private Progress progress;
    6058
    6159    public OKBExperimentUploadView() {
    6260      InitializeComponent();
    63       progressView = new ProgressView(this);
     61      progress = new Progress() {
     62        CanBeCanceled = false,
     63        ProgressState = ProgressState.Finished
     64      };
    6465    }
    6566
     
    9596      RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing);
    9697      RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed);
     98      progressView = new ProgressView(this, progress);
    9799    }
    98100
     
    100102      RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
    101103      RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
     104      if (progressView != null) {
     105        progressView.Content = null;
     106        progressView.Dispose();
     107        progressView = null;
     108      }
    102109      base.DeregisterContentEvents();
    103110    }
     
    191198        Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
    192199      } else {
    193         progress = new Progress();
    194200        progress.Status = "Refreshing algorithms and problems...";
    195         SetProgressView(progress);
     201        progress.ProgressState = ProgressState.Started;
    196202      }
    197203    }
     
    201207        Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
    202208      } else {
    203         FinishProgressView();
     209        progress.Finish();
    204210        SetEnabledStateOfControls();
    205211      }
     
    209215      var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync);
    210216      task.ContinueWith((t) => {
    211         FinishProgressView();
     217        progress.Finish();
    212218        PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception);
    213219      }, TaskContinuationOptions.OnlyOnFaulted);
     
    215221
    216222    private void UploadAsync() {
    217       progress = new Progress();
    218223      progress.Status = "Uploading runs to OKB...";
    219224      progress.ProgressValue = 0;
     
    221226      int i = 0;
    222227
    223       SetProgressView(progress);
    224       foreach (DataGridViewRow row in dataGridView.Rows) {
    225         selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault();
    226         selectedProblem = problems.Where(x => x.Name == row.Cells[problemColumnIndex].Value.ToString()).FirstOrDefault();
    227         if (selectedAlgorithm == null || selectedProblem == null) {
    228           throw new ArgumentException("Can't retrieve the algorithm/problem to upload");
    229         }
    230 
    231         OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);
    232         run.Store();
    233         i++;
    234         progress.ProgressValue = ((double)i) / count;
    235       }
    236       FinishProgressView();
     228      using (var view = new ProgressView(this, progress)) {
     229        foreach (DataGridViewRow row in dataGridView.Rows) {
     230          selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault();
     231          selectedProblem = problems.Where(x => x.Name == row.Cells[problemColumnIndex].Value.ToString()).FirstOrDefault();
     232          if (selectedAlgorithm == null || selectedProblem == null) {
     233            throw new ArgumentException("Can't retrieve the algorithm/problem to upload");
     234          }
     235
     236          OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);
     237          run.Store();
     238          i++;
     239          progress.ProgressValue = ((double)i) / count;
     240        }
     241      }
    237242      ClearRuns();
    238     }
    239 
    240     private void SetProgressView(IProgress progress) {
    241       if (InvokeRequired) {
    242         Invoke(new Action<IProgress>(SetProgressView), progress);
    243       } else {
    244         progressView.Progress = progress;
    245       }
    246     }
    247 
    248     private void FinishProgressView() {
    249       if (InvokeRequired) {
    250         Invoke(new Action(FinishProgressView));
    251       } else {
    252         progress.Finish();
    253       }
    254243    }
    255244
Note: See TracChangeset for help on using the changeset viewer.