I have tried a lot but I can't find out how to update a GUI element for example a TextBlock.Text
from an running Task on Windows Universal App for Windows IoT on Raspberry.
Is there any way to do this?
It should work out of the running task without stopping it.
According to an answer I have tried this:
Task t1 = new Task(() =>
{
while (1 == 1)
{
byte[] writeBuffer = { 0x41, 0x01, 0 }; // Buffer to write to mcp23017
byte[] readBuffer = new byte[3]; // Buffer to read to mcp23017
SpiDisplay.TransferFullDuplex(writeBuffer, readBuffer); // Send writeBuffer to mcp23017 and receive Results to readBuffer
byte readBuffer2 = readBuffer[2]; // extract the correct result
string output = Convert.ToString(readBuffer2, 2).PadLeft(8, '0'); // convert result to output Format
// Update the frontend TextBlock status5 with result
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
status6.Text = output;
});
}
});
t1.Start();
But I get the following 2 errors:
Error CS0103 The name 'CoreDispatcherPriority' does not exist in the current context
and
CS4014 Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
Am I doing something wrong using the code?