microsoft / microsoft/WindowsAppSDK
AppInstance.UnregisterKey() causes a failfast crash when called on a different thread than FindOrRegisterForKey(...) was called from
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
### Describe the bug
When I call AppInstance.UnregisterKey() from a different thread than FindOrRegisterForKey(...) was called from, for me it consistently immediately crashes the process with a `0xc0000409` code. It seems to happen when trying to reset a mutex, `m_keyCreationMutexLock`, inside `UnregisterKey()`.
If this is intended/expected behavior, it should at least be called out in the documentation for `FindOrRegisterForKey` and `UnregisterKey`. This was very frustrating to debug.
### Steps to reproduce the bug
Minimal reproduction:
`
AppInstance.FindOrRegisterForKey("key");
Thread.Sleep(3000);
new Thread(() =>
{
AppInstance.GetCurrent().UnregisterKey();
}).Start();`
### Expected behavior
The key will be registered and unregistered, without crashing the process.
### Screenshots
_No response_
### NuGet package version
2.0.1
### Packaging type
Packaged (MSIX)
### Windows version
Windows 11 version 24H2 (26100, June 2025 Update)
### IDE
Other
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction using AppInstance.FindOrRegisterForKey and AppInstance.UnregisterKey, then investigate the cross-thread call and the m_keyCreationMutexLock reset described in the report. Done means the key can be registered and unregistered from the shown threads without a process crash, or the thread requirement is clearly documented for both APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100