SevenDays
SevenDays

Reputation: 3768

how to create background thread in WP7 with timeout?

I'm using Mango, so I have background tasks. How can I make the thread that will process the data?(with timeout) I need to create thread for checking incoming messages.I need to set timeout for it.Thread must running in background on all pages.

I want something like

     public startApp() { 
     Thread th = new Thread(function_to_check,5)//last is  timeout 
}

Upvotes: 2

Views: 758

Answers (1)

William Melani
William Melani

Reputation: 4268

Put a DispatcherTimer in your App.xaml.cs file.

...

private static readonly DispatcherTimer myTimer = new DispatcherTimer();
 myTimer .Interval = TimeSpan.FromSeconds(5);
            myTimer .Tick += myTimerTick;
            myTimer .Start();

...

 private void myTimerTick(object sender, EventArgs e)
        {
           //do something here
        }

edit:

This allows you a single location to do what you want. If you need custom logic per page, you could create a switch statement where you check the current page

Or you could override PhoneApplicationPage with a page where you create this timer, and override the Tick function in each subpage.

Upvotes: 2

Related Questions