[GH-ISSUE #372] Recent change in ApplicationViewModel closes the app with error 2 #1677

Closed
opened 2026-03-01 18:47:24 +03:00 by kerem · 5 comments
Owner

Originally created by @vmrocha on GitHub (Aug 10, 2018).
Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/372

Originally assigned to: @NickeManarin on GitHub.

There is a recent change in the ApplicationViewModel file that is checking if the current window is loaded; if not, it closes the application. This is preventing the editor from opening on my computer.

Previous code:

if (Application.Current.Windows.Count == 0)
  Application.Current.Shutdown(2);

New code:

if (Application.Current.Windows.Cast<Window>().Where(window => window.IsLoaded && window.HasContent).Count() == 0)
  Application.Current.Shutdown(2);

I believe that change should be reverted.

Commit: github.com/vmrocha/ScreenToGif@3e0076a875

Originally created by @vmrocha on GitHub (Aug 10, 2018). Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/372 Originally assigned to: @NickeManarin on GitHub. There is a recent change in the ApplicationViewModel file that is checking if the current window is loaded; if not, it closes the application. *This is preventing the editor from opening on my computer.* Previous code: ``` if (Application.Current.Windows.Count == 0) Application.Current.Shutdown(2); ``` New code: ``` if (Application.Current.Windows.Cast<Window>().Where(window => window.IsLoaded && window.HasContent).Count() == 0) Application.Current.Shutdown(2); ``` I believe that change should be reverted. Commit: https://github.com/vmrocha/ScreenToGif/commit/3e0076a875f511445c05b047cc29948def7d6220
kerem 2026-03-01 18:47:24 +03:00
Author
Owner

@NickeManarin commented on GitHub (Aug 10, 2018):

Thank you for finding it out what is happening!

In a few hours, I'll release a new version with this fix.
(v2.14.1)

<!-- gh-comment-id:412138399 --> @NickeManarin commented on GitHub (Aug 10, 2018): Thank you for finding it out what is happening! In a few hours, I'll release a new version with this fix. (v2.14.1)
Author
Owner

@NickeManarin commented on GitHub (Aug 10, 2018):

I got a feedback from another user that has a Windows 7 machine with the same problem.
I could not get to reproduce this bug with my computer (with Windows 10).

<!-- gh-comment-id:412139286 --> @NickeManarin commented on GitHub (Aug 10, 2018): I got a feedback from another user that has a Windows 7 machine with the same problem. I could not get to reproduce this bug with my computer (with Windows 10).
Author
Owner

@vmrocha commented on GitHub (Aug 10, 2018):

I'm running Windows 10.

I believe that the person who wrote the new code wanted to check if the window that loaded had no content. On my computer, the Editor window has content, but it didn't finish loading yet.

<!-- gh-comment-id:412160722 --> @vmrocha commented on GitHub (Aug 10, 2018): I'm running Windows 10. I believe that the person who wrote the new code wanted to check if the window that loaded had no content. On my computer, the Editor window has content, but it didn't finish loading yet.
Author
Owner

@spietras commented on GitHub (Aug 10, 2018):

I changed that code because in my case (Windows 10) the app didn't close even after all windows were closed. Why? Because there actually were abstract windows (like Adorner): they don't have content.

I think the best solution would be to change window => window.IsLoaded && window.HasContent to just window => window.HasContent. I can't test that now, but I think it makes sense.

<!-- gh-comment-id:412167158 --> @spietras commented on GitHub (Aug 10, 2018): I changed that code because in my case (Windows 10) the app didn't close even after all windows were closed. Why? Because there actually were abstract windows (like Adorner): they don't have content. I think the best solution would be to change `window => window.IsLoaded && window.HasContent` to just `window => window.HasContent`. I can't test that now, but I think it makes sense.
Author
Owner

@vmrocha commented on GitHub (Aug 10, 2018):

Changing the code to:

if (Application.Current.Windows.Cast<Window>().Count(window => window.HasContent) == 0)
    Application.Current.Shutdown(2);

fixed the issue on my computer.

Window Version: 10.0.16299 Build 16299
.NET Framework Version installed: 4.7.02556

<!-- gh-comment-id:412171066 --> @vmrocha commented on GitHub (Aug 10, 2018): Changing the code to: ``` if (Application.Current.Windows.Cast<Window>().Count(window => window.HasContent) == 0) Application.Current.Shutdown(2); ``` fixed the issue on my computer. Window Version: 10.0.16299 Build 16299 .NET Framework Version installed: 4.7.02556
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ScreenToGif#1677
No description provided.