Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2523 for trunk/sources


Ignore:
Timestamp:
11/23/09 11:29:26 (15 years ago)
Author:
epitzer
Message:

Update data binding after collection changed (#805)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Grid/3.2/ClientForm.cs

    r2518 r2523  
    4646      InitializeComponent();
    4747      clientControllers = new List<ClientController>();
    48       nClientsControl.Value = Environment.ProcessorCount;
    49       clientControllerBindingSource.DataSource = clientControllers;
    50       UpdateControl();
     48      lock (clientControllers) {
     49        nClientsControl.Value = Environment.ProcessorCount;
     50        clientControllerBindingSource.DataSource = clientControllers;
     51        UpdateControl();
     52      }
    5153    }
    5254
    5355    private void startButton_Click(object sender, EventArgs e) {
    54       foreach (var client in clientControllers) {
    55         client.Client.Start(addressTextBox.Text);
     56      lock (clientControllers) {
     57        foreach (var client in clientControllers) {
     58          client.Client.Start(addressTextBox.Text);
     59        }
     60        UpdateControl();
    5661      }
    57       UpdateControl();
    5862    }
    5963
    6064    private void stopButton_Click(object sender, EventArgs e) {
    61       foreach (var client in clientControllers) {
    62         client.Client.Stop();
     65      lock (clientControllers) {
     66        foreach (var client in clientControllers) {
     67          client.Client.Stop();
     68        }
     69        UpdateControl();
    6370      }
    64       UpdateControl();
    6571    }
    6672
    6773    private void UpdateControl() {
    68       foreach (var client in clientControllers) {
    69         if (client.Client.Waiting) {
    70           startButton.Enabled = false;
    71           stopButton.Enabled = true;
    72           client.Status = "Waiting for engine";
    73         } else if (client.Client.Executing) {
    74           startButton.Enabled = false;
    75           stopButton.Enabled = true;
    76           client.Status = "Executing engine";
    77         } else if (client.Client.Stopped) {
    78           startButton.Enabled = true;
    79           stopButton.Enabled = false;
    80           client.Status = "Stopped";
     74      lock (clientControllers) {
     75        foreach (var client in clientControllers) {
     76          if (client.Client.Waiting) {
     77            startButton.Enabled = false;
     78            stopButton.Enabled = true;
     79            client.Status = "Waiting for engine";
     80          } else if (client.Client.Executing) {
     81            startButton.Enabled = false;
     82            stopButton.Enabled = true;
     83            client.Status = "Executing engine";
     84          } else if (client.Client.Stopped) {
     85            startButton.Enabled = true;
     86            stopButton.Enabled = false;
     87            client.Status = "Stopped";
     88          }
     89          client.Message = client.Client.StatusMessage;
    8190        }
    82         client.Message = client.Client.StatusMessage;
     91        clientControllerBindingSource.ResetBindings(false);
    8392      }
    84       clientGrid.Invalidate();
    8593    }
    8694
     
    9098
    9199    private void nClientsControl_ValueChanged(object sender, EventArgs e) {
    92       if (nClientsControl.Value < 0)
    93         nClientsControl.Value = 0;
    94       while (clientControllers.Count < nClientsControl.Value)
    95         clientControllers.Add(new ClientController() { Client = new GridClient() });
    96       while (clientControllers.Count > nClientsControl.Value) {
    97         try {
    98           clientControllers[clientControllers.Count - 1].Client.Stop();
    99           clientControllers.RemoveAt(clientControllers.Count - 1);
    100         } catch { }
     100      lock (clientControllers) {
     101        if (nClientsControl.Value < 0)
     102          nClientsControl.Value = 0;
     103        while (clientControllers.Count < nClientsControl.Value) {
     104          clientControllers.Add(new ClientController() { Client = new GridClient() });
     105        }
     106        while (clientControllerBindingSource.Count > nClientsControl.Value) {
     107          GridClient client = clientControllers.Last().Client;
     108          if (!client.Stopped)
     109            client.Stop();
     110          clientControllers.RemoveAt(clientControllerBindingSource.Count - 1);
     111        }
    101112      }
    102       clientGrid.Invalidate();
     113      clientControllerBindingSource.ResetBindings(false);
    103114    }
    104115  }
Note: See TracChangeset for help on using the changeset viewer.