Can we develop windows screen casting windows.media.miracast application as windows service that can run in background task ?

karthik kovi 25 Reputation points
2023-09-15T11:57:21.3133333+00:00

I am developing a screen casting application for Windows systems, utilizing Miracast technology. The primary goal is to ensure that the application runs continuously in the background and actively monitors the casting connection. Whenever a casting interruption occurs, the application should automatically initiate a recast process. I have successfully implemented this functionality using a Windows UWP (Universal Windows Platform) application and incorporated a timer watchdog feature to monitor the casting system.

However, there is an issue with the UWP application when it comes to running in the background. The problem arises because the timer appears to get stuck when the application transitions from the foreground to the background. This behavior disrupts the continuous monitoring and recasting functionality.

Now, I am seeking a potential solution to this problem. Is there a way to transform the screen casting functionality into a Windows service application? By doing so, I hope to ensure that the application can seamlessly operate in the background of Windows systems without experiencing the issues that arise with UWP applications. This would provide a more robust and reliable solution for monitoring and managing casting interruptions.

Developer technologies | Universal Windows Platform (UWP)
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-09-18T03:04:19.34+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I'm just talking from the UWP side, generally, UWP app will enter the suspended state when user minimized the app. You will have a very short time before the app get suspended.

    But now there is a way that could make UWP app continue to run when it is minimized. You just need to use the extended execution APIs and add a restricted capability -extendedExecutionUnconstrained.

    The code looks like this:

    var newSession = new ExtendedExecutionForegroundSession();
    newSession.Reason = ExtendedExecutionForegroundReason.Unconstrained;
    newSession.Description = "Long Running Processing";
    newSession.Revoked += SessionRevoked;
    ExtendedExecutionForegroundResult result = await newSession.RequestExtensionAsync();
    switch (result)
    {
        case ExtendedExecutionForegroundResult.Allowed:
            DoLongRunningWork();
            break;
    
        default:
        case ExtendedExecutionForegroundResult.Denied:
            DoShortRunningWork();
            break;
    }
    
    

    Please refer to Run in the background indefinitely for more detailed information.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.