Changeset 11468 for branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmServiceNode.cs
- Timestamp:
- 10/16/14 03:57:49 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmServiceNode.cs
r11465 r11468 93 93 } 94 94 95 protected virtual void Execute(ServiceParameterCollection parameters ) {95 protected virtual void Execute(ServiceParameterCollection parameters, CancellationToken token) { 96 96 if (Template == null) throw new InvalidOperationException("Template is null"); 97 97 … … 120 120 algorithm.Stopped += Algorithm_Stopped; 121 121 algorithm.Start(); 122 waitHandles[algorithm].WaitOne(); 123 124 // retrieve results 125 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) { 126 IResult result = null; 127 if (algorithm.Results.TryGetValue(p.Name, out result)) { 128 p.Value = result.Value; 129 } 130 } 131 132 lock (locker) { 133 waitHandles[algorithm].Dispose(); 134 waitHandles.Remove(algorithm); 135 Runs.Add(algorithm.Runs.ToArray()[0]); 122 if (WaitHandle.WaitAny(new WaitHandle[] { waitHandles[algorithm], token.WaitHandle }) == 1) { 123 // retrieve results 124 foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) { 125 IResult result = null; 126 if (algorithm.Results.TryGetValue(p.Name, out result)) { 127 p.Value = result.Value; 128 } 129 } 130 131 lock (locker) { 132 waitHandles[algorithm].Dispose(); 133 waitHandles.Remove(algorithm); 134 Runs.Add(algorithm.Runs.ToArray()[0]); 135 } 136 } else { // cancellation 137 algorithm.Stop(); 138 lock (locker) { 139 waitHandles[algorithm].Dispose(); 140 waitHandles.Remove(algorithm); 141 } 136 142 } 137 143 } … … 191 197 IServicePort s = port as IServicePort; 192 198 if (s != null) { 193 s. Called += ServicePort_Called;199 s.ProcessParameters += ServicePort_ProcessParameters; 194 200 } 195 201 } … … 203 209 IServicePort s = port as IServicePort; 204 210 if (s != null) { 205 s. Called -= ServicePort_Called;211 s.ProcessParameters -= ServicePort_ProcessParameters; 206 212 } 207 213 } … … 212 218 UpdateParameter((IInputPort)sender); 213 219 } 214 private void ServicePort_ Called(object sender, EventArgs<ServiceParameterCollection> e) {215 Execute(e.Value );220 private void ServicePort_ProcessParameters(object sender, EventArgs<ServiceParameterCollection, CancellationToken> e) { 221 Execute(e.Value, e.Value2); 216 222 } 217 223 #endregion
Note: See TracChangeset
for help on using the changeset viewer.