private static void Run(TaskWrapper parent, CancellationToken cancel, Color background) { //NOTE: This method is running on an arbitrary thread try { // Create viewport ViewportOffline viewport = new ViewportOffline(background); List <ICameraPoolCamera> cameras = new List <ICameraPoolCamera>(); while (!cancel.IsCancellationRequested) { // Add/Remove items AddRemoveItems(parent, viewport, cameras); if (cameras.Count == 0) { // Hang out for a bit, then try again. No need to burn up the processor //TODO: UseAutoResetEvent (triggered by another thread in CameraPool.Add()) //http://stackoverflow.com/questions/382173/what-are-alternative-ways-to-suspend-and-resume-a-thread Thread.Sleep(450 + StaticRandom.Next(100)); continue; } MoveVisuals(viewport); #region Take pictures //TODO: If it takes a long time to get through these cameras, then maybe the visuals should be moved after every couple cameras foreach (ICameraPoolCamera camera in cameras) { if (cancel.IsCancellationRequested) { return; } if (camera.IsOn) { var location = camera.GetWorldLocation_Camera(); IBitmapCustom bitmap = viewport.GetSnapshot(location.Item1, location.Item2.Standard, location.Item2.Orth, camera.PixelWidthHeight); camera.StoreSnapshot(bitmap); } } #endregion Thread.Sleep(0); // not sure if this is useful or not //Thread.Yield(); } } catch (Exception) { // Don't leak errors, just go away } }
private static void Run(TaskWrapper parent, CancellationToken cancel, Color background) { //NOTE: This method is running on an arbitrary thread try { // Create viewport ViewportOffline viewport = new ViewportOffline(background); List<ICameraPoolCamera> cameras = new List<ICameraPoolCamera>(); while (!cancel.IsCancellationRequested) { // Add/Remove items AddRemoveItems(parent, viewport, cameras); if (cameras.Count == 0) { // Hang out for a bit, then try again. No need to burn up the processor //TODO: UseAutoResetEvent (triggered by another thread in CameraPool.Add()) //http://stackoverflow.com/questions/382173/what-are-alternative-ways-to-suspend-and-resume-a-thread Thread.Sleep(450 + StaticRandom.Next(100)); continue; } MoveVisuals(viewport); #region Take pictures //TODO: If it takes a long time to get through these cameras, then maybe the visuals should be moved after every couple cameras foreach (ICameraPoolCamera camera in cameras) { if (cancel.IsCancellationRequested) { return; } if (camera.IsOn) { var location = camera.GetWorldLocation_Camera(); IBitmapCustom bitmap = viewport.GetSnapshot(location.Item1, location.Item2.Standard, location.Item2.Orth, camera.PixelWidthHeight); camera.StoreSnapshot(bitmap); } } #endregion Thread.Sleep(0); // not sure if this is useful or not //Thread.Yield(); } } catch (Exception) { // Don't leak errors, just go away } }