I have been tasked at porting a LOB desktop app from .NET 4.5.2 to Windows 10 UWP. In normal Win32 apps an app runs until the user closes the app (service and application). But when reading up on UWP apps all docs I find say that there is no way to prevent an app from suspending (only temporary or until quota exceeded). I understand this on Mobile/Tablet, but not on a desktop machine with performance and power available.
A common answer to this problem is to use a "real" server (usually a web server). But our app is used in the field where internet is not available. So we need the server/service to run on a desktop machine.
The best option so far I found is a UWP app with built in background task asking for deferral. But as I understand this still offer no guarantees regarding suspend. Only some vague info that "you probably don't get suspended since it is a desktop machine with lots of resources in the global pool" ...
And I don't like to keep the LOB service app in .NET and clients in UWP since they share a lot of code that can't be reused between .NET and UWP.
So, anyone that got a definite answer/reference to wether it is possible to prevent suspend for service style UWP app/task running on Win10 desktop machine?
A similar uservoice has been raised on wpdev.uservoice.com where Microsoft is listening suggestions. You are highly encouraged to vote on it, add your comments and monitor it.
I believe preventing suspend or not should be decided by user, but there is no way to do that. And I agree, in some special scenarios, it makes sense.
But currently the Application lifecycle for UWP is very clear about the suspended state. On Desktop family, UWP apps suspend when they are minimized or when Windows enters a low power state.
[Update]
One more possible solution you may not know is a new feature introduced in Windows 10 - Extended execution session.
Currently there is no official sample about this feature, but you can check Jerry Nixon and Andy Wigley’s MVA session about application lifecycle(#13). And here is Q&A record for that session where you can find a sample code. You can download the ppt included in the MVA session which includes the following code for your quick reference:
private async void OnSuspending(object sender, SuspendingEventArgs args)
{
var deferral = e.SuspendingOperation.GetDeferral(); using (var session = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.SavingData })
{
session.Description = "Upload Data";
session.Revoked += (s, e) => { Log("Save incomplete"); }; try
{
if (await session.RequestExtensionAsync() == ExtendedExecutionResult.Denied) // takes 3 seconds
UploadBasicData();
else // takes 8 seconds
await UploadDataAsync(session); Log("Save complete");
}
catch { Log("Save failed"); }
finally { deferral.Complete(); }
}
}
But as Jerry mentioned, there is still no guarantee it is 100% reliable.
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