Skip to content

[Peek] Terminate Preview Handlers Processes#40116

Merged
lei9444 merged 7 commits intomainfrom
users/davidegiacometti/peek-terminate-previewhandler
Jul 14, 2025
Merged

[Peek] Terminate Preview Handlers Processes#40116
lei9444 merged 7 commits intomainfrom
users/davidegiacometti/peek-terminate-previewhandler

Conversation

@davidegiacometti
Copy link
Collaborator

@davidegiacometti davidegiacometti commented Jun 18, 2025

Summary of the Pull Request

This is an attempt to release Preview Handlers instantiated by Peek and close the related processe.

⚠️ Note that even if the PR improve the current behavior, the solution doesn't work 100% of times.
I noticed that sometimes the process gets leaked also when Preview Handler is used in Explorer 🤔

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Ported the same fix applied to CmdPal to ensure the process is terminated gracefully instead of being killed: [CmdPal] Close Gracefully #39589
  • Attempt to cleanup Preview Handlers and close the relative process

Validation Steps Performed

Tested manually:

  • Preview through some Excel and Word files
  • Close Peek window
  • Excel and Word processes are closed

@davidegiacometti davidegiacometti force-pushed the users/davidegiacometti/peek-terminate-previewhandler branch from 1d5879c to 419b463 Compare June 18, 2025 20:24
@davidegiacometti davidegiacometti marked this pull request as draft June 18, 2025 20:27
@davidegiacometti davidegiacometti self-assigned this Jun 21, 2025
@davidegiacometti davidegiacometti marked this pull request as ready for review June 21, 2025 13:57
@crutkas crutkas added Needs-Review This Pull Request awaits the review of a maintainer. Product-Peek Refers to Peek Powertoys labels Jul 8, 2025
}
CloseHandle(m_hProcess);

CloseHandle(hProcess);
Copy link
Contributor

Choose a reason for hiding this comment

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

m_hProcess should be closed too

{
foreach (var factory in HandlerFactories.Values)
{
Marshal.FinalReleaseComObject(factory);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding try-catch here to guard against exceptions.

@davidegiacometti
Copy link
Collaborator Author

Hi @lei9444, thanks for the review! I have addressed the feedback.

@davidegiacometti davidegiacometti requested a review from lei9444 July 12, 2025 10:10
@lei9444 lei9444 merged commit 227c5d8 into main Jul 14, 2025
14 checks passed
@davidegiacometti davidegiacometti deleted the users/davidegiacometti/peek-terminate-previewhandler branch July 14, 2025 17:57
@yeelam-gordon yeelam-gordon added this to the PowerToys 0.93 milestone Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Review This Pull Request awaits the review of a maintainer. Product-Peek Refers to Peek Powertoys

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants