Sign in to follow this  
Followers 0

c# [C#][XMAL] Updating the app


4 posts in this topic

Posted

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;

Void UPDATE()

{

countDown --;

if (countDown == 600)

}

that type of thing.

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

Share this post


Link to post
Share on other sites

Posted

take a look at Dispatcher Timer

Share this post


Link to post
Share on other sites

Posted

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".

Share this post


Link to post
Share on other sites

Posted

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);

			  SomeCountDownProperty--;

	   }

}

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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.