Skip to content

Fixed bug: Icon disposed#241

Closed
Kyome22 wants to merge 1 commit into
mainfrom
fix-bug-icon-disposed
Closed

Fixed bug: Icon disposed#241
Kyome22 wants to merge 1 commit into
mainfrom
fix-bug-icon-disposed

Conversation

@Kyome22
Copy link
Copy Markdown
Collaborator

@Kyome22 Kyome22 commented Sep 8, 2025

Context of Contribution

  • Bug Fix
  • Refactoring
  • New Feature
  • Others

Summary of the Proposal

#236

Checklist

  • This PR does not contain commits of multiple contexts.
  • Code follows proper indentation and naming conventions.
  • Works correctly in both dark theme and light theme.
  • Works correctly on any device.

@Kyome22 Kyome22 mentioned this pull request Sep 12, 2025
8 tasks
@Kyome22
Copy link
Copy Markdown
Collaborator Author

Kyome22 commented Sep 13, 2025

I haven't been able to reproduce the actual issue locally, so I can't be certain if this has fixed the issue.

@mor39a Do you have any ideas on how to reproduce the issue?

@mor39a
Copy link
Copy Markdown
Collaborator

mor39a commented Sep 13, 2025

@mor39a Do you have any ideas on how to reproduce the issue?

I never had this bug, so I have no idea how to reproduce it. However, I will check it out.

@mor39a
Copy link
Copy Markdown
Collaborator

mor39a commented Sep 14, 2025

Hi @Kyome22, what version of Windows are you using? I did some research, but I wasn't able to replicate it (I'm using Windows 10). Issues #236 and #233 reported using Windows 11 24H2. It's possible that the different way updates are handled means we can't replicate the error.

Since neither of us has been able to replicate the bug, I suggest asking the issue #236 reporter to test it whenever we make progress. It might be a bit tedious, but I can't think of any other solution.


Although I'm not really sure, I suspect that the notifyIcon object has been disposed for some reason, leaving the notifyIcon.Icon object inaccessible. Adding a conditional on lines 257 and 270 of ContextMenuManager.cs, that checks if notifyIcon is disposed, I hope that fixes the problem.

https://github.com/Kyome22/RunCat365/blob/02c7ac261ffae9ca41b680a5d6738a1bc705201b/RunCat365/ContextMenuManager.cs#L255-L258

https://github.com/Kyome22/RunCat365/blob/02c7ac261ffae9ca41b680a5d6738a1bc705201b/RunCat365/ContextMenuManager.cs#L270


I will continue investigating and keep you posted.

if (icons.Count <= current) current = 0;
notifyIcon.Icon = icons[current];
var icon = icons[current];
if (icon is not null && !icon.IsDisposed)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this defined? Icon doesn't have this property and doesn't compile

@muko
Copy link
Copy Markdown
Contributor

muko commented Nov 8, 2025

I was able to reproduce this issue while debugging commit fdf0100 on the main branch, so I'm reporting it here.
My environment: Windows 11 24H2 (26100.6584).
It seems to happen more often after the PC wakes up from sleep.

System.ObjectDisposedException
HResult=0x80131622
Message=Cannot access a disposed object.
Object name: 'Icon'.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.NotifyIcon.UpdateIcon(Boolean showIconInTray)
at RunCat365.ContextMenuManager.SetNotifyIconText(String text) in C:\Projects\RunCat\RunCat365\ContextMenuManager.cs:line 267
at RunCat365.RunCat365ApplicationContext.FetchSystemInfo(CPUInfo cpuInfo, MemoryInfo memoryInfo, List`1 storageValue) in C:\Projects\RunCat\RunCat365\Program.cs:line 183
at RunCat365.RunCat365ApplicationContext.FetchTick(Object state, EventArgs e) in C:\Projects\RunCat\RunCat365\Program.cs:line 209
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

image image

@Kyome22 Kyome22 closed this Dec 1, 2025
@Kyome22 Kyome22 deleted the fix-bug-icon-disposed branch January 7, 2026 09:18
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.

4 participants