日期:2014-05-17  浏览次数:20854 次

an interface that was marshalled for a different thread.这个exception什么意思?


刚用C#这个问题各种烦,这几天一直遇到,求大神仔细讲一下,还有怎么避免?
------解决方案--------------------
可以详细一点啊
------解决方案--------------------
引用:
可以详细一点啊

我建一个timer
TimerHandle = new TimerElapsedHandler(MyTimer);
            timespace = TimeSpan.FromMilliseconds(5000);    //设定的Timer时间(毫秒)
            DelayTimer = ThreadPoolTimer.CreatePeriodicTimer(TimerHandle, timespace); 

如果时间长,如5000ms就会在new WriteableBitmap跳出这个异常。
如果时间设置短 就会在await m_mediaCaptureMgr.CapturePhotoToStreamAsync(_encodingProps, _imageStream);这儿异常。


 private async void MyTimer(ThreadPoolTimer timer)
        {
            
            _imageStream = new InMemoryRandomAccessStream();
            await m_mediaCaptureMgr.CapturePhotoToStreamAsync(_encodingProps, _imageStream);

            await _imageStream.FlushAsync();
            bitmap = new WriteableBitmap(300, 200);
            
            _imageStream.Seek(0);
            bitmap.SetSource(_imageStream);
            image.Source = bitmap;
            
        }

------解决方案--------------------
求大神 解答呀!!!
C#我弱爆了呀
------解决方案--------------------
我同样的代码放到button下面没问题,来人解答呀!