public ServiceController() { _sensor = new WiFiSensor(stopThread: _sensorStop, pauseThread: _sensorPause, playThread: _sensorPlay, output: _sensorOutputLocalizerInput); _localizer = new LocationLocalizer(stopThread: _localizerStop, pauseThread: _localizerPause, playThread: _localizerPlay, input: _sensorOutputLocalizerInput, algorithm: _localizationAlgorithm); _sensorState = ThreadState.Playing; _localizerState = ThreadState.Playing; _sensorThread = new Thread(new ThreadStart(_sensor.WiFiSensorLoop)); _localizerThread = new Thread(new ThreadStart(_localizer.LocationLocalizerLoop)); _sensorThread.IsBackground = true; _localizerThread.IsBackground = true; _sensorThread.Name = "WiFiSensorThread"; _localizerThread.Name = "LocationLocalizerThread"; }
public void LocationLocalizerTest() { var stopThread = new AutoResetEvent(false); var pauseThread = new AutoResetEvent(false); var playThread = new AutoResetEvent(false); var localizer = new LocationLocalizer(stopThread: stopThread, pauseThread: pauseThread, playThread: playThread, input: new SensorToLocalizer<SensorOutput>(), algorithm: new SimpleLocalization()); var localizerDelegate = new ThreadStart(localizer.LocationLocalizerLoop); var localizerThread = new Thread(localizerDelegate); localizerThread.Start(); Log.Debug("Main Thread go to sleep"); Thread.Sleep(8000); Log.Debug("Main thread is awake"); Log.Debug("Pause LocationLocalizer"); pauseThread.Set(); Log.Debug("Main Thread go to sleep"); Thread.Sleep(8000); Log.Debug("Main thread is awake"); Log.Debug("Restart LocationLocalizer"); playThread.Set(); Log.Debug("Main Thread go to sleep"); Thread.Sleep(8000); Log.Debug("Main thread is awake"); Log.Debug("Stop LocationLocalizer"); stopThread.Set(); Log.Debug("Wait for LocationLocalizer"); localizerThread.Join(); Log.Debug("LocationLocalizer has spontaneously terminated"); }