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

Check GPUController is started before getting GPU info #1502

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions LenovoLegionToolkit.Lib/Controllers/GPUController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class GPUController
private string? _performanceState;

public event EventHandler<GPUStatus>? Refreshed;
public bool Started { get; private set; } = false;
Ace-Radom marked this conversation as resolved.
Show resolved Hide resolved

public bool IsSupported()
{
Expand Down Expand Up @@ -72,6 +73,7 @@ public async Task StartAsync(int delay = 1_000, int interval = 5_000)
_refreshCancellationTokenSource = new CancellationTokenSource();
var token = _refreshCancellationTokenSource.Token;
_refreshTask = Task.Run(() => RefreshLoopAsync(delay, interval, token), token);
Started = true;
Ace-Radom marked this conversation as resolved.
Show resolved Hide resolved
}

public async Task StopAsync(bool waitForFinish = false)
Expand Down Expand Up @@ -102,6 +104,7 @@ public async Task StopAsync(bool waitForFinish = false)

_refreshCancellationTokenSource = null;
_refreshTask = null;
Started = false;
Ace-Radom marked this conversation as resolved.
Show resolved Hide resolved

if (Log.Instance.IsTraceEnabled)
Log.Instance.Trace($"Stopped");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ private static unsafe int GetCpuBaseClock()

private async Task<GPUInfo> GetGPUInfoAsync()
{
if (gpuController.IsSupported() && !gpuController.Started)
Ace-Radom marked this conversation as resolved.
Show resolved Hide resolved
await gpuController.StartAsync();

if (await gpuController.GetLastKnownStateAsync().ConfigureAwait(false) is GPUState.PoweredOff or GPUState.Unknown)
return GPUInfo.Empty;

Expand Down