Skip to content

Fix disposed icon crash#268

Merged
Kyome22 merged 2 commits into
mainfrom
fix-disposed-icon-crash-clean
Jan 7, 2026
Merged

Fix disposed icon crash#268
Kyome22 merged 2 commits into
mainfrom
fix-disposed-icon-crash-clean

Conversation

@Kyome22
Copy link
Copy Markdown
Collaborator

@Kyome22 Kyome22 commented Jan 7, 2026

Context of Contribution

  • Bug Fix
  • Refactoring
  • New Feature
  • Others

fix #236

Summary of the Proposal

Since I have established a way to reproduce the issue, I have identified the cause and fixed it.
There is no need to manually dispose of the NotifyIcon's Icon.

Reason for the new feature

Checklist

  • This PR does not contain commits of multiple contexts.
  • Code follows proper indentation and naming conventions.
  • Implemented using only APIs that can be submitted to the Microsoft Store.
  • Works correctly in both dark theme and light theme.
  • Works correctly on any device.

Kyome22 and others added 2 commits January 7, 2026 23:27
Root cause:
Icons obtained from Resources.ResourceManager are managed resources
that should not be manually disposed. When we called Dispose() on
these icons:
1. NotifyIcon still held references to the disposed icons
2. Any access to NotifyIcon properties (Text, Icon, etc.) would
   trigger ObjectDisposedException
3. This commonly occurred during app launch, sleep/wake, and theme
   changes when SetIcons() ran concurrently with AdvanceFrame()

Solution:
Remove all icon.Dispose() calls in SetIcons() and Dispose() methods.
ResourceManager handles the lifecycle of these resources, and the
GC will properly clean them up.

This fix resolves crashes reported in GitHub issues where users
experienced "Cannot access a disposed object. Object name: 'Icon'"
errors during startup and after sleep/wake cycles.

Testing:
Verified with stress testing (100 iterations of rapid icon switching
with 5ms delays) that previously reproduced the crash 100% of the
time. After this fix, no crashes occurred in 15+ test runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Kyome22 Kyome22 merged commit adf8711 into main Jan 7, 2026
@Kyome22 Kyome22 deleted the fix-disposed-icon-crash-clean branch January 7, 2026 15:58
@Kyome22 Kyome22 mentioned this pull request Jan 7, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: .net error

1 participant