Im WPF
응용 프로그램에서 사용하고 일부 작업을 수행하기 위해 DepthFrameReady
이벤트를 수신합니다. UI 블록을 피하기 위해 나는 async
이벤트를 만들었고 메신저는 데이터 조작을 만든 함수를 "기다리고"있습니다.비동기 이벤트에서 개체 삭제 C# WPF
Rigth 이제 메시지 점점 비주얼 스튜디오 메신저에서 출력 창에서 :
경고 : IMAGEFRAME 인스턴스 내가
DepthImageFrame
(넣어 처분 할 많은 것들을 시도
배치되지 않았습니다 논리 내부 using
블록, 비동기 함수가 끝날 때 콜백 등).하지만 처음 호출 한 후에는 null을 보내고 있으므로 ...
비동기/대기 이벤트에 개체를 배치하는 가장 어려운 방법은 무엇입니까?.
MyWindow.xaml.cs
private async void KinectSensorFound_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
// as suggested in Zoran Answer
await Task.Run(() =>
{
using (DepthImageFrame DataDepthImageFrame = e.OpenDepthImageFrame())
{
UpdateUserDepthInfo(DataDepthImageFrame);
}
});
}
public void UpdateUserDepthInfo(DepthImageFrame DataDepthImage)
{
var TimeNow = DateTime.Now;
if ((DateTime.Now - PreviusTime).Milliseconds <= 50)
return;
syncronizationContext.Post(new SendOrPostCallback(o =>
{
if (chckbxDepthImage.IsChecked == true)
{
chckbxColorImage.IsChecked = false;
// This method is called in my bussines logic to do a transformation with the frame
BitmapSource DepthBitMapSource = Controller.getInfoOfDepthUser(DataDepthImage);
DepthCanvas.Background = new ImageBrush(DepthBitMapSource);
}
else
{
DepthCanvas.Children.Clear();
DepthCanvas.Background = new SolidColorBrush(Colors.Transparent);
}
DepthUserInfo = Controller.DoGetInfoDepthUser(DataDepthImage);
lblDepthUser.Content = string.Format("{0:0.00} mts", DepthUserInfo/1000);
}), DataDepthImage);
PreviusTime = TimeNow;
}
KinectHelper.cs
public BitmapSource getBitmapOfDepth(DepthImageFrame DataImageFrame)
{
DepthImagePixel[] ImageDepth = new DepthImagePixel[0];
int DepthDistance;
depthReturnStruct DepthReturn = new depthReturnStruct();
if (DataImageFrame != null)
{
ImageDepth = new DepthImagePixel[DataImageFrame.PixelDataLength];
DataImageFrame.CopyDepthImagePixelDataTo(ImageDepth); // exception here
//... other code
}
return bitmapDepth;
}
Task.Run을 기다린 후 dispose를 호출하지 않는 이유는 무엇입니까? – Steve
스티브에게 감사 드리며 제안을 시도했지만 'DataDepthImageFrame'을 사용하는 메소드를 호출 할 때 다음 오류 (** System.ObjectDisposedException **)가 표시됩니다. –