Skip to content
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

resume launch execution if game is launched first #2505

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

Conversation

qhy040404
Copy link
Member

Description

Related Issue

Checklist

  • The target PR branch is develop branch

@qhy040404 qhy040404 requested review from Copilot and Lightczx March 2, 2025 11:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR introduces logic to wait for the game process to exit after launch if it's already running, helping to ensure that subsequent operations depend on the game no longer being active.

  • Added an unsafe asynchronous method (WaitForGameProcessExitAsync) to spin-wait on the game process exit.
  • Updated using directives to include necessary game launching handler namespaces.

Reviewed Changes

File Description
src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs Added process exit waiting logic with an unsafe spin wait implementation

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +374 to +376
unsafe
{
SpinWaitPolyfill.SpinWhile(&LaunchExecutionEnsureGameNotRunningHandler.IsGameRunning);
Copy link
Preview

Copilot AI Mar 2, 2025

Choose a reason for hiding this comment

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

The use of an unsafe spin-wait may block the thread indefinitely if LaunchExecutionEnsureGameNotRunningHandler.IsGameRunning remains true. Consider refactoring this logic to use an asynchronous waiting mechanism or include a timeout to avoid potential deadlocks.

Suggested change
unsafe
{
SpinWaitPolyfill.SpinWhile(&LaunchExecutionEnsureGameNotRunningHandler.IsGameRunning);
const int timeoutMilliseconds = 30000; // 30 seconds timeout
const int delayMilliseconds = 100; // 100 milliseconds delay
int elapsedMilliseconds = 0;
while (LaunchExecutionEnsureGameNotRunningHandler.IsGameRunning())
{
if (elapsedMilliseconds >= timeoutMilliseconds)
{
throw new TimeoutException("Waiting for the game process to exit timed out.");
}
await Task.Delay(delayMilliseconds).ConfigureAwait(false);
elapsedMilliseconds += delayMilliseconds;

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@qhy040404 qhy040404 changed the title watch process if hutao is launched after game resume launch execution if game is launched first Mar 2, 2025
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.

1 participant