question

DUCOSEricDEXIP-6148 avatar image
0 Votes"
DUCOSEricDEXIP-6148 asked ·

Running a background thread when minimized

Hi,

Before telling me to use BackgroundTask component, I want to say that I already think about, but I do not see how to use it without rewriting a whole of things with the risk of breaking other things...

My need is to have the same as what is running good on android platform (whereas I am not an adept of android platform...but in this case, this works on android, but I cannot make working on my preferred Windows Platform !!!)

The need is to get a background thread launched at startup continue to work even if the app is minimzed or put in background.
My thread has to many interaction with some foreground data and services used in the front UI, and I think that I cannot move it to a UWP Background task component...and I am not sure that it could run in infinite in such a way...

I searched on the Web and I thought that I found the solution on this Microsoft documentation page:
https://docs.microsoft.com/en-us/windows/uwp/launch-resume/run-in-the-background-indefinetly

Can someone help me implement that in my Xamarin Form app ?
I tried to follow instructions, but I missed someting because it does not recognize the restricited capability in my manifest when I try to deploy locally my app.

I must say also that the app is NOT deployed in the Microsoft Store. It is manually deployed in a side by side way locally on entreprise devices.

Regards.

dotnet-xamarinformswindows-uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered ·

Hello, Welcome to Micorosoft Q&A,

Can someone help me implement that in my Xamarin Form app ? I tried to follow instructions, but I missed someting because it does not recognize the restricited capability in my manifest when I try to deploy locally my app.

The document Run in the background indefinitely is suit for your scenario, for running background tasks indefinitely, you need enable restricited capability

I will share the complete manifest content that make restricited capability available, please refer the following content to edit your own manifest.

double click manifest-> press F7 edit with xml-> add the rescap namespace under the package attribute then specific it in the IgnorableNamespaces attribute.


 <Package
     ... 
     xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"  
     IgnorableNamespaces="uap mp rescap"> 
 ...
   <Capabilities> 
     <rescap:Capability Name="extendedBackgroundTaskTime"/>
   </Capabilities>
 </Package>


Please note

Some of the longer-running tasks also have a check to ensure that the background task is not sitting idle or using memory. In the Windows Creators Update (version 1703), the extendedBackgroundTaskTime restricted capability was introduced to remove these limits.

Please make sure your app's target min version large than 1703.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.











·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DUCOSEricDEXIP-6148 avatar image
0 Votes"
DUCOSEricDEXIP-6148 answered ·

Hey guy,

I do not understand what happened.

What you described is what I had done before...and I had a problem when deploying...

But I have done again and now it works (computer mysteries !!!)..or perhaps I did not do exactly the same thing..

I just had to move the ExtendedExecutionForegroundSession as a global variable in my UWP App class and now, when I minimized my app, the background thread continue to work.

Thanks for your time.

Regards.


I just replace your capabilities with this one that seems to me more appropriate according to the Microsoft documentation: "extendedExecutionUnconstrained"

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.