조금 n00b 질문 나는 여전히 많은 StackOverflow 답변을 읽고 이해하지 않습니다.WriteableBitmap 작업의 WritePixels
변수는 Kinect에서 25 번 업데이트 된 바이트 배열입니다. UI 구성 요소가 없습니다.
WriteableBitmap 및 WritePixels가 동일한 작업의 스레드에서 호출 된 것으로 생각했습니다. 하지만 여전히 System.InvalidOperationException이 발생합니다. 각 루프에 대해 새로운 WriteableBitmap을 만들면 오류가 없습니다.
WriteableBitmap을 효율적으로 재사용하려면 어떻게해야합니까?
private async Task DoJob(TimeSpan dueTime, TimeSpan interval, CancellationToken token) {
if (dueTime > TimeSpan.Zero)
await Task.Delay(dueTime, token);
WriteableBitmap bitmap = NewColorBitmap(colorW, colorH);
// Repeat this loop until cancelled.
while (!token.IsCancellationRequested) {
try {
bitmap.WritePixels(
new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight),
colorData, bitmap.PixelWidth * Bgra32BytesPerPixel, 0);
}
catch(Exception ex){
// System.InvalidOperationException:
// The calling thread cannot access this object
// because a different thread owns it.
}
// Wait to repeat again.
if (interval > TimeSpan.Zero)
await Task.Delay(interval, token);
}
}
이 코드가 병렬입니까? –