Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13767


Ignore:
Timestamp:
04/15/16 09:37:26 (9 years ago)
Author:
abeham
Message:

#2457: fixed cross-thread exception

Location:
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Menu/0_Config/30_DownloadFromOkbMenuItem.cs

    r13748 r13767  
    5656    protected override void OnToolStripItemSet(EventArgs e) {
    5757      base.OnToolStripItemSet(e);
    58       ToolStripItem.Enabled = MainForm.ExpertSystem.Problem.ProblemId != -1;
     58      SetToolStripItemEnabled(MainForm.ExpertSystem.Problem.ProblemId != -1);
    5959      MainForm.ExpertSystem.Problem.ProblemChanged += OnProblemChanged;
    6060      MainForm.ExpertSystem.DownloadStarted += OnDownloadStarted;
     
    6262
    6363    private void OnProblemChanged(object sender, EventArgs e) {
    64       ToolStripItem.Enabled = MainForm.ExpertSystem.Problem.ProblemId != -1;
     64      SetToolStripItemEnabled(MainForm.ExpertSystem.Problem.ProblemId != -1);
    6565    }
    6666
    6767    private void OnDownloadStarted(object sender, EventArgs<IProgress> e) {
    68       ToolStripItem.Enabled = false;
     68      SetToolStripItemEnabled(false);
    6969      e.Value.ProgressStateChanged += DownloadProgressOnStateChanged;
    7070    }
     
    7373      var progress = (IProgress)sender;
    7474      if (progress.ProgressState == ProgressState.Finished || progress.ProgressState == ProgressState.Canceled) {
    75         ToolStripItem.Enabled = true;
     75        SetToolStripItemEnabled(true);
    7676        progress.ProgressStateChanged -= DownloadProgressOnStateChanged;
    7777      }
    7878    }
     79
     80    private void SetToolStripItemEnabled(bool state) {
     81      if (ToolStripItem.Owner != null && ToolStripItem.Owner.InvokeRequired) { ToolStripItem.Owner.Invoke((Action<bool>)SetToolStripItemEnabled, state); return; }
     82      ToolStripItem.Enabled = state;
     83    }
    7984  }
    8085}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Toolbar/DownloadFromOKBToolbarItem.cs

    r13748 r13767  
    5050    protected override void OnToolStripItemSet(EventArgs e) {
    5151      base.OnToolStripItemSet(e);
    52       ToolStripItem.Enabled = MainForm.ExpertSystem.Problem.ProblemId != -1;
     52      SetToolStripItemEnabled(MainForm.ExpertSystem.Problem.ProblemId != -1);
    5353      MainForm.ExpertSystem.Problem.ProblemChanged += OnProblemChanged;
    5454      MainForm.ExpertSystem.DownloadStarted += OnDownloadStarted;
     
    5656
    5757    private void OnProblemChanged(object sender, EventArgs e) {
    58       ToolStripItem.Enabled = MainForm.ExpertSystem.Problem.ProblemId != -1;
     58      SetToolStripItemEnabled(MainForm.ExpertSystem.Problem.ProblemId != -1);
    5959    }
    6060
    6161    private void OnDownloadStarted(object sender, EventArgs<IProgress> e) {
    62       ToolStripItem.Enabled = false;
     62      SetToolStripItemEnabled(false);
    6363      e.Value.ProgressStateChanged += DownloadProgressOnStateChanged;
    6464    }
     
    6767      var progress = (IProgress)sender;
    6868      if (progress.ProgressState == ProgressState.Finished || progress.ProgressState == ProgressState.Canceled) {
    69         ToolStripItem.Enabled = true;
     69        SetToolStripItemEnabled(true);
    7070        progress.ProgressStateChanged -= DownloadProgressOnStateChanged;
    7171      }
    7272    }
     73
     74    private void SetToolStripItemEnabled(bool state) {
     75      if (ToolStripItem.Owner != null && ToolStripItem.Owner.InvokeRequired) { ToolStripItem.Owner.Invoke((Action<bool>)SetToolStripItemEnabled, state); return; }
     76      ToolStripItem.Enabled = state;
     77    }
    7378  }
    7479}
Note: See TracChangeset for help on using the changeset viewer.