Changeset 5106 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockJob.cs
- Timestamp:
- 12/14/10 16:52:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/Mocks/MockJob.cs
r5104 r5106 9 9 using System.Drawing; 10 10 using System.Threading; 11 using System.Diagnostics; 11 12 12 13 namespace HeuristicLab.Clients.Hive.Slave.Tests { … … 45 46 46 47 private int ms = 1000; //ms 47 public MockJob(int ms) { 48 private bool spinWait; 49 public MockJob(int ms, bool spinWait) { 48 50 this.ms = ms; 51 this.spinWait = spinWait; 49 52 } 50 53 public MockJob() { } 51 54 [StorableConstructor] 52 55 protected MockJob(bool deserializing) { } 53 protected MockJob(MockJob original, Cloner cloner) : base(original, cloner) { 56 protected MockJob(MockJob original, Cloner cloner) 57 : base(original, cloner) { 54 58 this.ComputeInParallel = original.ComputeInParallel; 55 59 this.IndexInParentOptimizerList = original.IndexInParentOptimizerList; … … 92 96 93 97 public virtual void Start() { 94 DateTime start = DateTime.Now; 95 do { 96 Thread.SpinWait(1000); 97 this.ExecutionTime = DateTime.Now - start; 98 } while (ExecutionTime.TotalMilliseconds < ms); 99 Stop(); 100 OnJobStopped(); 98 new Thread(Run).Start(); 99 } 100 101 private void Run() { 102 try { 103 if (spinWait) { 104 Stopwatch watch = new Stopwatch(); 105 watch.Start(); 106 do { 107 Thread.SpinWait(1000); 108 } while (watch.ElapsedMilliseconds < ms); 109 watch.Stop(); 110 } else { 111 Thread.Sleep(ms); 112 } 113 Stop(); 114 OnJobStopped(); 115 } 116 catch (Exception e) { 117 this.ExecutionState = Core.ExecutionState.Stopped; 118 OnJobFailed(); 119 } 101 120 } 102 121
Note: See TracChangeset
for help on using the changeset viewer.