In a UWP C# app, need background (ie. worker) thread to use UI thread to display an image. But can't figure out how to compile Dispatcher.RunAsync()
.
using Foundation;
using System;
using UIKit;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.Threading;
using System.Windows.Threading; <<<<<<<<<< gets error
using Windows.UI.Core; <<<<<<<<<< gets error
public async static void process_frame()
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// "the name dispatcher does not exist in current context"
//UI code here:
display_frame();
});
}
public void display_frame()
{
var data = NSData.FromArray(System_Hub_Socket.packet_frame_state.buffer);
UIImageView_camera_frame.Image = UIImage.LoadFromData(data);
}
Latest method
public async static void process_frame( /* ax obsolete: byte[] camera_frame_buffer, int frame_size_bytes */ )
{
await Task.Run( () => { viewcontroller.display_frame(); } );
}
// [3]
// Copies latest frame from camera to UIImageView on iPad.
// UI THREAD
public Task display_frame()
{
var data = NSData.FromArray ( System_Hub_Socket.packet_frame_state.buffer);
<<<<<< ERROR
UIImageView_camera_frame.Image = UIImage.LoadFromData( data );
return null;
}
Error from the latest method