private void StartLiveViewThread() { try { _totalframes = 0; _framestart = DateTime.Now; bool retry = false; int retryNum = 0; Log.Debug("LiveView: Liveview started"); do { try { LiveViewManager.StartLiveView(SelectedPortableDevice); } catch (DeviceException deviceException) { Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Visible; })); if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY || deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy) { Thread.Sleep(200); if (!IsVisible) { break; } Log.Debug("Retry live view :" + deviceException.ErrorCode.ToString("X")); retry = true; retryNum++; } else { throw; } } } while (retry && retryNum < 35); if (IsVisible) { _timer.Start(); oper_in_progress = false; _retries = 0; Log.Debug("LiveView: Liveview start done"); } } catch (Exception exception) { Log.Error("Unable to start liveview !", exception); StaticHelper.Instance.SystemMessage = "Unable to start liveview ! " + exception.Message; //MessageBox.Show("Unable to start liveview !"); //ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.LiveViewWnd_Hide); } Dispatcher.BeginInvoke(new Action(delegate { grid_wait.Visibility = Visibility.Hidden; })); Dispatcher.BeginInvoke(new Action(delegate { image1.Visibility = Visibility.Visible; })); }
private void StartLiveViewThread() { try { bool retry = false; int retryNum = 0; Log.Debug("LiveView: Liveview started"); do { try { LiveViewManager.StartLiveView(CameraDevice); } catch (DeviceException deviceException) { if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY || deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy) { Thread.Sleep(200); if (!IsVisible) { break; } Log.Debug("Retry live view :" + deviceException.ErrorCode.ToString("X")); retry = true; retryNum++; } else { throw; } } } while (retry && retryNum < 35); if (IsVisible) { _oper_in_progress = false; _liveviewtimer.Start(); Log.Debug("LiveView: Liveview start done"); } } catch (Exception exception) { Log.Error("Unable to start liveview !", exception); StaticHelper.Instance.SystemMessage = "Unable to start liveview ! " + exception.Message; //MessageBox.Show("Unable to start liveview !"); //ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.LiveViewWnd_Hide); } }
private void StopLiveViewThread() { try { _totalframes = 0; _framestart = DateTime.Now; bool retry = false; int retryNum = 0; Log.Debug("LiveView: Liveview stopping"); do { try { LiveViewManager.StopLiveView(SelectedPortableDevice); } catch (DeviceException deviceException) { Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Visible; })); if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY || deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy) { Thread.Sleep(500); Log.Debug("Retry live view stop:" + deviceException.ErrorCode.ToString("X")); retry = true; retryNum++; } else { throw; } } } while (retry && retryNum < 35); } catch (Exception exception) { Log.Error("Unable to stop liveview !", exception); StaticHelper.Instance.SystemMessage = "Unable to stop liveview ! " + exception.Message; } Dispatcher.Invoke(new Action(delegate { grid_wait.Visibility = Visibility.Hidden; })); Dispatcher.Invoke(new Action(delegate { image1.Visibility = Visibility.Hidden; })); }
void _liveviewtimer_Elapsed(object sender, ElapsedEventArgs e) { if (_oper_in_progress) { return; } _oper_in_progress = true; try { if (!Freeze) { LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice); } Dispatcher.Invoke(new Action(DisplayLiveView)); } catch (Exception exception) { Log.Debug("Error get live view data *Astro ", exception); } _oper_in_progress = false; }
private void StopLiveViewThread() { try { bool retry = false; int retryNum = 0; Log.Debug("LiveView: Liveview stopping"); do { try { LiveViewManager.StopLiveView(CameraDevice); } catch (DeviceException deviceException) { if (deviceException.ErrorCode == ErrorCodes.ERROR_BUSY || deviceException.ErrorCode == ErrorCodes.MTP_Device_Busy) { Thread.Sleep(500); Log.Debug("Retry live view stop:" + deviceException.ErrorCode.ToString("X")); retry = true; retryNum++; } else { throw; } } } while (retry && retryNum < 35); } catch (Exception exception) { Log.Error("Unable to stop liveview !", exception); StaticHelper.Instance.SystemMessage = "Unable to stop liveview ! " + exception.Message; } }
private void GetLiveImage() { if (oper_in_progress) { return; } oper_in_progress = true; _totalframes++; try { LiveViewData = LiveViewManager.GetLiveViewImage(SelectedPortableDevice); } catch (Exception) { _retries++; oper_in_progress = false; return; } if (LiveViewData == null || LiveViewData.ImageData == null) { _retries++; oper_in_progress = false; return; } Dispatcher.Invoke(new Action(delegate { try { WriteableBitmap preview; if (LiveViewData != null && LiveViewData.ImageData != null) { MemoryStream stream = new MemoryStream(LiveViewData.ImageData, LiveViewData.ImagePosition, LiveViewData.ImageData.Length - LiveViewData.ImagePosition); using (var bmp = new Bitmap(stream)) { preview = BitmapFactory.ConvertToPbgra32Format( BitmapSourceConvert.ToBitmapSource(bmp)); Bitmap newbmp = bmp; WriteableBitmap writeableBitmap; writeableBitmap = BitmapFactory.ConvertToPbgra32Format( BitmapSourceConvert.ToBitmapSource(newbmp)); //DrawGrid(writeableBitmap); writeableBitmap.Freeze(); image1.BeginInit(); image1.Source = writeableBitmap; image1.EndInit(); } stream.Close(); } } catch (Exception exception) { Log.Error(exception); _retries++; oper_in_progress = false; } })); _retries = 0; oper_in_progress = false; }