Free cookie consent management tool by TermsFeed Policy Generator

Changeset 244


Ignore:
Timestamp:
05/13/08 22:21:18 (17 years ago)
Author:
gkronber
Message:

fixed #137 (together with changes for #149)

File:
1 edited

Legend:

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

    r228 r244  
    3838namespace HeuristicLab.Grid {
    3939  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    40   public partial class ClientForm : Form, IClient {
     40  public partial class ClientForm : Form {
    4141    private ChannelFactory<IEngineStore> factory;
    4242    private System.Timers.Timer fetchOperationTimer;
     
    4444    private Guid currentGuid;
    4545    private ProcessingEngine currentEngine;
     46    private object connectionLock = new object();
    4647
    4748    public ClientForm() {
     
    8283    private void stopButton_Click(object sender, EventArgs e) {
    8384      fetchOperationTimer.Stop();
    84       factory.Abort();
     85      if(currentEngine != null)
     86        currentEngine.Abort();
     87      lock(connectionLock) {
     88        IAsyncResult closeResult = factory.BeginClose(null, null);
     89        factory.EndClose(closeResult);
     90      }
    8591      statusTextBox.Text = "Stopped";
    8692      stopButton.Enabled = false;
     
    9298      fetchOperationTimer.Stop();
    9399      try {
    94         if(factory.State != CommunicationState.Opened) {
    95           ResetConnection();
     100        bool success;
     101        lock(connectionLock) {
     102          if(factory.State != CommunicationState.Opened) {
     103            ResetConnection();
     104          }
     105          success = engineStore.TryTakeEngine(out currentGuid, out engineXml);
    96106        }
    97         if(engineStore.TryTakeEngine(out currentGuid, out engineXml)) {
     107        if(success) {
    98108          currentEngine = RestoreEngine(engineXml);
    99109          if(InvokeRequired) { Invoke((MethodInvoker)delegate() { statusTextBox.Text = "Executing engine"; }); } else statusTextBox.Text = "Executing engine";
    100110          currentEngine.Finished += delegate(object src, EventArgs args) {
    101             byte[] resultXml = SaveEngine(currentEngine);
    102             engineStore.StoreResult(currentGuid, resultXml);
    103             currentGuid = Guid.Empty;
    104             currentEngine = null;
    105             fetchOperationTimer.Interval = 100;
    106             fetchOperationTimer.Start();
     111            if(factory.State == CommunicationState.Opened && !currentEngine.Canceled) {
     112              byte[] resultXml = SaveEngine(currentEngine);
     113              lock(connectionLock) {
     114                engineStore.StoreResult(currentGuid, resultXml);
     115              }
     116              currentGuid = Guid.Empty;
     117              currentEngine = null;
     118              fetchOperationTimer.Interval = 100;
     119              fetchOperationTimer.Start();
     120            }
    107121          };
    108122          currentEngine.Execute();
     
    112126          fetchOperationTimer.Start();
    113127        }
    114       } catch(Exception ex) {
     128      } catch(TimeoutException timeoutException) {
     129        currentEngine = null;
     130        currentGuid = Guid.Empty;
     131        fetchOperationTimer.Interval = 5000;
     132        fetchOperationTimer.Start();
     133      } catch(CommunicationException communicationException) {
    115134        currentEngine = null;
    116135        currentGuid = Guid.Empty;
     
    118137        fetchOperationTimer.Start();
    119138      }
    120     }
    121     public void Abort(Guid guid) {
    122       throw new NotSupportedException();
    123     }
    124     public bool IsRunningEngine(Guid guid) {
    125       throw new NotSupportedException();
    126139    }
    127140    private ProcessingEngine RestoreEngine(byte[] engine) {
Note: See TracChangeset for help on using the changeset viewer.