Skip to content

Code Quality: Introduced a wrapper for non-blocking await on a sync method #17100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0x5bfa
Copy link
Member

@0x5bfa 0x5bfa commented May 5, 2025

Resolved / Related Issues

Steps used to test these changes

  1. Open Files app
  2. Enable the setting to run Files in the background
  3. Start debebugging Files
  4. Close the window
  5. Launch Files from Start Menu

@0x5bfa
Copy link
Member Author

0x5bfa commented May 5, 2025

Requesting your review @dongle-the-gadget @hez2010

}
});

HANDLE* pEventHandles = stackalloc HANDLE[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you even need to allocate a stack here? I thought your HANDLE variable is in stack already.

Copy link
Member Author

Choose a reason for hiding this comment

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

Related to your 2nd comment, it looks like you can't take address of a local variable that goes thru an async lambda/function. The current code doesn't have async and initially did so this can be refactored but IIUC if we wanna use async void we may have to do this.

IntPtr eventHandle = CreateEvent(IntPtr.Zero, true, false, null);

Task.Run(() =>
STATask.RunAsSync(() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why async void isn't desirable here?

Copy link
Member Author

Choose a reason for hiding this comment

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

So you mean adding Wait() in that helper method instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean making it an async lambda and then await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants