Jump to content


[C#][XMAL] Updating the app

c# xmal

  • Please log in to reply
3 replies to this topic

#1 DrakeN2k



  • Joined: 04-December 10

Posted 18 January 2013 - 19:48

I am trying to build a Windows 8 metro style app using C# and XMAL is there a way to call a methord X times a second instead of when clicked , when touched est.

For example

when user hits a button X , a count down will appear on a screen , which will count down from 10 to 0.

Dont worry about getting the count down to appear just how to count down a int

int countDown;

countDown --;

if (countDown == 600)


that type of thing.

Everything i have seen on MSDN was on button press , event stuff.

#2 johndotcom83



  • Joined: 08-October 02

Posted 18 January 2013 - 19:51

take a look at Dispatcher Timer

#3 OP DrakeN2k



  • Joined: 04-December 10

Posted 18 January 2013 - 20:13

Thanks what about more advanced stuff instead of just a clock, What if i want to just say call a method from the very start and keep calling it forever?

Just like Update in XNA?

My situation im building a calculate i have a number of buttons , i want to show the current equsaion the user has imputed , just say 5 + 7 * 4 + 6.

I can call a method every time for every button , but why not something that gets called once every update. or can you do it once evey "button press".

#4 dotnetnelson



  • Joined: 04-December 12

Posted 18 January 2013 - 20:28

A couple of things:

- You'll likely want to databind the count down value to a property, and use the INotifyPropertyChanged interface to automatically reflect your back end changes to your front end view
- You'll want to maintain UI thread affinity. If you can guarantee you'll raise the initial method on the UI thread (which you can because its a button click) then it makes sense to await a Task because it captures the ambient SynchronizationContext and saves you the UI thread marshaling.

Id do something like

public async Task Countdown()
	   SomeCountDownProperty = 10;
	   while (SomeCountdownProperty != 0)
			  await Task.Delay(1000);

Then on your button click event simply do:

await Countdown();

SomeCountdownProperty is a property which raises a PropertyChanged event when the value changes. It is always raised on the UI thread because the continuation is always run on the current synchronization context (which is CoreDispatcher because we are raised from a Click handler)