Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App activation fires multiple times when launching multiple files #5066

Open
tipa opened this issue Jan 24, 2025 · 1 comment
Open

App activation fires multiple times when launching multiple files #5066

tipa opened this issue Jan 24, 2025 · 1 comment

Comments

@tipa
Copy link

tipa commented Jan 24, 2025

Describe the bug

I have an app that can open image files. Users can associate image file endings (e.g. .jpg) with my app or open the image files in my app using the context menu in the Windows explorer and use "open with...".
When users select multiple files (e.g. 5 image files) and then open them all in my app with a single click on the "Open" option in the context menu, my app is activated 5 times and in with each activation, the FileActivatedEventArgs.Files contains all 5 files in each activation.

Steps to reproduce the bug

<uap:Extension Category="windows.fileTypeAssociation">
    <uap:FileTypeAssociation Name="images">
        <uap:SupportedFileTypes>
            <uap:FileType ContentType="image/jpeg">.jpg</uap:FileType>
            <uap:FileType ContentType="image/jpeg">.jpeg</uap:FileType>
            ...
        </uap:SupportedFileTypes>
    <uap:DisplayName>Images</uap:DisplayName>
    </uap:FileTypeAssociation>
</uap:Extension>
[STAThread]
static void Main()
{
    var keyInstance = AppInstance.FindOrRegisterForKey("main");
    if (keyInstance.IsCurrent)
    {
        keyInstance.Activated += (_, e) =>
        {
            // handle activation here
        };
        Application.Start(p =>
        {
            var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
            SynchronizationContext.SetSynchronizationContext(context);
            _ = new App();
        });
    }
    else { keyInstance.RedirectActivationToAsync(AppInstance.GetCurrent().GetActivatedEventArgs()).GetAwaiter().GetResult(); }
}

Expected behavior

My app should only be activated once.

Screenshots

No response

NuGet package version

Windows App SDK 1.6.3: 1.6.250108002

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

IDE

Visual Studio 2022

Additional context

This problem was not present in UWP. My app was only activated once in UWP, even when multiple files were opened

@julien-bertolini
Copy link

Exact same problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants