RobWarning wrote:Hi Haroldpulcher,
thanks for your code example.
unfortunately this is not working for the raspberry 2 on IOT.
maybe that is more useful to you
do this in your MainPage
Code: Select all
private void Page_Loaded(object sender, RoutedEventArgs e)
timer = new Windows.UI.Xaml.DispatchTimer();
timer.Tick += Timer_Tick;
timer.Interval = TimeSpan.FromMilliseconds(1000.0);
private void Timer_Tick(object sender, object e)
// do something in UI thread context
// e.g. polling your values you want to display on UI
otherwise you have to take the Dispatcher of the UI element you want access to (of your MainPage for example).
if you use a "standalone" none-UI-thread, you can pass the Dispatcher of the UI element to your thread, to be able to access to the Dispatcher to execute/access to UI properties via RunAsync...
and by the way, nobody force you to use "RunAsync()" with "await"...
you can use it without await as well... and in that case it is not blocking the UI thread... that's because it is called async
only in case you need to lineup executions in correct order (because the result od the execution is needed for the followed execution), the easiest way to do so is using "await", but it is indeed not always the best idea then.
and "var" should be available, as long you use all needed references and usings.
GerritV wrote:You can have the main thread/object (ui) register for an event and then in your gpio thread raise an event. You decide what data to pass, even an object.
Read up on RaiseEvent and AddHandler
A lot of overhead and complexity when raising an event is what you really needed.
Because in essence you are blocking your timer thread until the await is satisfied. Might or might not have repercussions from that, such as missed counts.
an event does not necessarily executes in UI thread context, in case you build your own events from within none-UI-context-threads... in that case you have to switch your execution into UI thread context first to do UI element access via one of the RunAsync calls from an UI elements Dispatcher.