diff --git a/server/src/Hubs/OscilloscopeHub.cs b/server/src/Hubs/OscilloscopeHub.cs index 66c3a94..38da0db 100644 --- a/server/src/Hubs/OscilloscopeHub.cs +++ b/server/src/Hubs/OscilloscopeHub.cs @@ -212,11 +212,10 @@ public class OscilloscopeHub : Hub, IOscilloscopeHub var key = (board.ID.ToString(), Context.ConnectionId); - if (_scanTasks.TryRemove(key, out var scanInfo)) + if (_scanTasks.TryRemove(key, out var taskInfo)) { - scanInfo.CTS.Cancel(); - if (scanInfo.ScanTask != null) await scanInfo.ScanTask; - scanInfo.CTS.Dispose(); + taskInfo.CTS.Cancel(); + if (taskInfo.ScanTask != null) taskInfo.ScanTask.Wait(); var result = await client.SetCaptureEnable(false); if (!result.IsSuccessful) diff --git a/src/components/Oscilloscope/OscilloscopeManager.ts b/src/components/Oscilloscope/OscilloscopeManager.ts index 71bf682..23f79ad 100644 --- a/src/components/Oscilloscope/OscilloscopeManager.ts +++ b/src/components/Oscilloscope/OscilloscopeManager.ts @@ -84,7 +84,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState( clearHub(); }); - function initHub() { + async function initHub() { if (oscilloscopeHub.value) return; const connection = AuthManager.createHubConnection("OscilloscopeHub"); @@ -96,7 +96,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState( connection, oscilloscopeReceiver, ); - connection.start(); + await connection.start(); oscilloscopeHub.value = { connection, proxy }; } @@ -252,12 +252,12 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState( alert.warn("当前没有正在进行的捕获操作", 2000); return; } - isCapturing.value = false; const release = await operationMutex.acquire(); try { const proxy = getHubProxy(); const stopped = await proxy.stopCapture(); if (!stopped) throw new Error("无法停止捕获"); + isCapturing.value = false; alert.info("捕获已停止", 2000); } catch (error) { alert.error("停止捕获失败", 3000); diff --git a/src/stores/Peripherals/RotaryEncoder.ts b/src/stores/Peripherals/RotaryEncoder.ts index 28a43b4..7dd11b7 100644 --- a/src/stores/Peripherals/RotaryEncoder.ts +++ b/src/stores/Peripherals/RotaryEncoder.ts @@ -30,7 +30,7 @@ export const useRotaryEncoder = defineStore("RotaryEncoder", () => { clearHub(); }); - function initHub() { + async function initHub() { if (rotaryEncoderHub.value) return; const connection = AuthManager.createHubConnection("RotaryEncoderHub"); const proxy = @@ -39,7 +39,7 @@ export const useRotaryEncoder = defineStore("RotaryEncoder", () => { connection, rotaryEncoderReceiver, ); - connection.start(); + await connection.start(); rotaryEncoderHub.value = { connection, proxy }; }