App autorun with system UWP C#

Dmitriy Borodiy 116 Reputation points
2021-08-10T20:26:03.557+00:00

Hello everyone!
I have a question about the autostart of the application.
When an application is launched along with the system, it is launched in the taskbar, but the application window does not open immediately. Only after clicking on the application icon on the taskbar, the window opens and the application continues to work.

How can I make the application window open immediately after starting the application along with the system?

protected override async void OnActivated(IActivatedEventArgs args)
        {
            try
            {
                Frame rootFrame = Window.Current.Content as Frame;

                if(args.Kind == ActivationKind.StartupTask)
                {
                    var users = await User.FindAllAsync();

                    if(users != null)
                    {
                        UserInformation.currentUser = users[0];
                    }

                    if(rootFrame == null)
                    {
                        rootFrame = new Frame();

                        rootFrame.NavigationFailed += OnNavigationFailed;

                        if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                        {
                            //TODO: Load state from previously suspended application
                        }

                        // Place the frame in the current Window
                        Window.Current.Content = rootFrame;
                    }

                    if(rootFrame.Content == null)
                    {
                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation
                        // parameter
                        rootFrame.Navigate(typeof(WidgetsFeed), null);
                    }
                    // Ensure the current window is active
                    Window.Current.Activate();

                    var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
                    coreTitleBar.ExtendViewIntoTitleBar = true;
              }
              catch
              {

              }
 }
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,051 Reputation points Microsoft Vendor
    2021-08-11T08:00:20.34+00:00

    Hello,

    Welcome to Microsoft Q&A!

    When an application is launched along with the system, it is launched in the taskbar, but the application window does not open immediately.

    Yes, this is the expected behavior. As mentioned in the document - StartupTask Class : If the user consents, the UWP app will then start on startup or user log in. Note that UWP startup apps will start minimized.

    How can I make the application window open immediately after starting the application along with the system?

    I have to say that currently, there is no API is designed to bring UWP app to the foreground programmatically.

    Thank you.


    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful