void ShutdownInternalService() { if (_queue != null) { if (_streamPort != null) { _streamPort.Post(new Shutdown()); _streamPort = null; } ResourceManagerPort.Post(new FreeExecutionResource(_queue)); _queue = null; } }
IEnumerator <ITask> ReplaceHandler(Replace replace) { _state = replace.Body; replace.ResponsePort.Post(DefaultReplaceResponseType.Instance); SendNotification(_submgrPort, replace); if (_streamPort != null) { _streamPort.Post(new Shutdown()); _streamPort = null; } if (!string.IsNullOrEmpty(_state.CaptureFile)) { _streamPort = SaveStream.Create(_state.CaptureFile, _state.Quality, _queue); } yield break; }
void TimeHandler(DateTime signal) { if (_shutdown || _reader.BaseStream.Position >= _reader.BaseStream.Length) { return; } int length = _reader.ReadInt32(); byte[] buffer = _reader.ReadBytes(length); using (MemoryStream stream = new MemoryStream(buffer, false)) { Frame frame = new Frame(); frame.Image = new Bitmap(stream); frame.TimeStamp = _currFrame; _port.Post(frame); } if (_reader.BaseStream.Position >= _reader.BaseStream.Length) { Activate( Arbiter.Receive(false, TimeoutPort(2000), delegate(DateTime t) { Frame frame = new Frame(); frame.Image = null; frame.TimeStamp = _currFrame + TimeSpan.FromSeconds(2); _port.Post(frame); } ) ); return; } DateTime lastFrame = _currFrame; _currFrame = DateTime.FromBinary(_reader.ReadInt64()); TimeSpan offset = _currFrame - lastFrame; int ms = (int)Math.Round(offset.TotalMilliseconds); if (ms <= 0) { _timePort.Post(_currFrame); } else { ms = Math.Min(ms, 2000); Activate( Arbiter.Receive(false, TimeoutPort(ms), delegate(DateTime t) { _timePort.Post(t); } ) ); } }