Changeset 244
- Timestamp:
- 05/13/08 22:21:18 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Grid/ClientForm.cs
r228 r244 38 38 namespace HeuristicLab.Grid { 39 39 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)] 40 public partial class ClientForm : Form , IClient{40 public partial class ClientForm : Form { 41 41 private ChannelFactory<IEngineStore> factory; 42 42 private System.Timers.Timer fetchOperationTimer; … … 44 44 private Guid currentGuid; 45 45 private ProcessingEngine currentEngine; 46 private object connectionLock = new object(); 46 47 47 48 public ClientForm() { … … 82 83 private void stopButton_Click(object sender, EventArgs e) { 83 84 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 } 85 91 statusTextBox.Text = "Stopped"; 86 92 stopButton.Enabled = false; … … 92 98 fetchOperationTimer.Stop(); 93 99 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); 96 106 } 97 if( engineStore.TryTakeEngine(out currentGuid, out engineXml)) {107 if(success) { 98 108 currentEngine = RestoreEngine(engineXml); 99 109 if(InvokeRequired) { Invoke((MethodInvoker)delegate() { statusTextBox.Text = "Executing engine"; }); } else statusTextBox.Text = "Executing engine"; 100 110 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 } 107 121 }; 108 122 currentEngine.Execute(); … … 112 126 fetchOperationTimer.Start(); 113 127 } 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) { 115 134 currentEngine = null; 116 135 currentGuid = Guid.Empty; … … 118 137 fetchOperationTimer.Start(); 119 138 } 120 }121 public void Abort(Guid guid) {122 throw new NotSupportedException();123 }124 public bool IsRunningEngine(Guid guid) {125 throw new NotSupportedException();126 139 } 127 140 private ProcessingEngine RestoreEngine(byte[] engine) {
Note: See TracChangeset
for help on using the changeset viewer.