2012-03-27 1 views
0

내 앱에서 바코드 스캔 기능이 있습니다. 기본 페이지에 바코드 버튼이 있습니다. 사용자는이를 클릭하고 바코드 스캔 페이지으로갑니다. 그것은 다시 이동할 때, 나는 그 말을 메시지 상자를 얻을 : 바코드 스캔보기에서 뒤로 이동할 때 인스턴스가 공유 리소스에 대해 처리됩니다.

This instance has been disposed. Possibly because another component required a shared resource. 

은 내가 PhotoCamera을 배치하고, 바코드 스캔 페이지의 OnNavigatedFrom 방법으로 모든 이벤트를 취소 만, 여전히 같은 일을 얻는다.

나는 코드에 들어갔다 및이 방법에 문제 발견 :

at Microsoft.Devices.Camera.InvokeAndRemapExceptions(Action a) 
at Microsoft.Devices.PhotoCamera.get_IsFocusSupported() 
at Microsoft.Devices.PhotoCamera.Focus() 
at WP7.ScanBarCode.BarCode.cam_AutoFocusCompleted(Object sender, CameraOperationCompletedEventArgs e) 
at Microsoft.Devices.Camera.<>c__DisplayClass21`1.<SafeFireEvent>b__1f(Object ignored) 
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
at System.Threading.ThreadPool.WorkItem.doWork(Object o) 
at System.Threading.Timer.ring() 

어떤 아이디어 :

PhotoCamera _cam; 
VideoBrush _videoBrush = new VideoBrush(); 
Stopwatch watch = new Stopwatch(); 
int _nbTry; 
Result result = null; 
void cam_AutoFocusCompleted(object sender, CameraOperationCompletedEventArgs e) 
     { 
      if (result == null) 
      { 
      try 
      { 
       _nbTry++; 
       watch.Reset(); 
       watch.Start(); 

       while ((result == null) && (watch.ElapsedMilliseconds < 1500) && _cam != null) 
       { 
        var binaryBitmap = GetBitmapFromVideo(_cam); 
        if (binaryBitmap != null) 
        { 
         try 
         { 
          result = BarCodeManager.ZXingReader.decode(binaryBitmap); 
         } 
         catch 
         { 
          // Wasn't able to find a barcode 
         } 
        } 
       } 

       if (result != null) 
       { 
        BarCodeManager._onBarCodeFound(result.Text); 
       } 
       else 
       { 
        if (_cam != null) 
        { 
         _cam.Focus(); 
        } 
       } 
      } 
      catch (Exception exc) 
      { 
       BarCodeManager._onError(exc); 
      } 
     } 
     } 

잡혀 다음과 같은 예외가 스택 트레이스가가요를? 감사!

+0

에뮬레이터에서 메시지 상자가 표시되면 콜 스택을 끊어 붙여 넣을 수 있습니까? –

+0

내 대답을보세요! – MAXE

답변

2

처음으로 바코드 스캔 페이지을 남겨두면 PhotoCamera을 처분 할 수 있습니다.

그냥 PhotoCamera 개체를 처리하는 경우, 당신은 바코드 스캔 페이지를 다시 올 때이 오류를 얻을 것이다 다음 PhotoCamera 개체를 처리하는

This instance has been disposed. Possibly because another component required a shared resource. 

시도를하고 또한 모든 이벤트 위임, 같은 Initialized 또는 관련 :

// Release the camera object: 
PhotoCamera.Dispose(); 

// Remove initialization event: 
PhotoCamera.Initialized -= PhotoCamera_Initialized; 

// For example, you must remove also the events linked to the camera management (e.g. when you press camera buttons): 
CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed; 

콜이 폐기 코드 당신은 OnNavigatedFrom 전자에 들어갈 때 바코드 스캔 페이지의 통풍구가 제대로 작동해야합니다.

관련 문제