I want to create a background task for updating a GEO location every 15 mins.
I'm using a background task and a timer, when I have the location I want to update the db every 15 minutes.
The problem is in WindowsRuntimeComponent ( used for background task) is not support with WCF data services communication : answer is here
So I decided to create background task in the same project, but the run method is not firing
I took the same step for adding the background task, when I took new project WindowsRuntimeComponent,
public void Run(IBackgroundTaskInstance taskInstance){
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
updatelocation();
deferral.Complete();
}
How should I add a background task without creating a new project?
I think you should make a timer base event on app launch page. Which will affect all the time when your app is in running. And it will definitely work. I used same for xaml C# based store app. And also you can add a configurable parameter in setting charm if user want to change the =refresh time then he/she can.
You can use WCF web service in background task. Try below given code.
public sealed class TestClass : IBackgroundTask
{
void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
updatelocation();
deferral.Complete();
}
}
public IAsyncOperation updatelocation()
{
return updatelocationHelper().AsAsyncOperation();
}
private async Task<string> updatelocationHelper()
{
var wcfClient = new MyWcfClient();
var content = await wcfClient.updatelocationAsync(wcf_service_url_here);
return content;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With