microsoft / microsoft/WindowsAppSDK
App activation fires multiple times when launching multiple files
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
### 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
```
.jpg
.jpeg
...
Images
```
[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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the AppInstance.FindOrRegisterForKey and Activated handling in the Main example, then reproduce the packaged Windows App SDK 1.6.3 case by opening multiple image files from Windows Explorer. Trace how FileActivatedEventArgs.Files is delivered across activations; done means one activation for the selection, with all selected files available once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100