Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window App store > new project WindowsRuntimeComponent for background is not working with WCF data service

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?

like image 452
patel Avatar asked Nov 21 '13 10:11

patel


2 Answers

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.

like image 91
Mihir Joshi Avatar answered Nov 04 '22 21:11

Mihir Joshi


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;
}
like image 1
Farhan Ghumra Avatar answered Nov 04 '22 19:11

Farhan Ghumra