我制作了一个创建线程并在该线程中创建图像的程序:
private async void GetCamera()
{
....
tk = new Task(MyAwesomeTask);
tk.Start();
}
private async void MyAwesomeTask()
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(0.5));
SavePhoto1();
}
}
private void SavePhoto1()
{
try
{
WriteableBitmap wb1 = new WriteableBitmap(320, 240);//throw exception
}catch (Exception ee)
{
String s = ee.ToString();
}
}
但是线
WriteableBitmap wb1 = new WriteableBitmap(320, 240);
抛出异常:
s="System.Exception:应用程序调用了为不同线程编组的接口。(来自 HRESULT 的异常:0x8001010E (RPC_E_WRONG_THREAD))\r\n 在 Windows.UI.Xaml.Media.Imaging.WriteableBitmap..ctor( Int32 pixelWidth, Int32 pixelHeight)\r\n at TestVideo.MainPage.SetImageFromStream() in ...\MainPage.xaml.cs:line 500\r\n at TestVideo.MainPage.SavePhoto1() in ....\MainPage .xaml.cs:第 145 行"
我需要做什么?