I've made a program that creates a thread and in that thread create image:
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();
}
}
But line
WriteableBitmap wb1 = new WriteableBitmap(320, 240);
throws exception:
s="System.Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))\r\n at 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:line 145"
What I need to do?