From 4caec1b732a45c26e1bb70eb75a6bc7b924adaee Mon Sep 17 00:00:00 2001 From: pypy Date: Thu, 21 Jan 2021 11:34:01 +0900 Subject: [PATCH] lock --- CpuMonitor.cs | 22 ++++++++++++++-------- Discord.cs | 7 +++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CpuMonitor.cs b/CpuMonitor.cs index 89ea5d91..3794d7b5 100644 --- a/CpuMonitor.cs +++ b/CpuMonitor.cs @@ -62,21 +62,27 @@ namespace VRCX internal void Exit() { - _timer.Change(-1, -1); - _performanceCounter?.Dispose(); + lock (this) + { + _timer.Change(-1, -1); + _performanceCounter?.Dispose(); + } } private void TimerCallback(object state) { - try + lock (this) { - if (_performanceCounter != null) + try + { + if (_performanceCounter != null) + { + CpuUsage = _performanceCounter.NextValue(); + } + } + catch { - CpuUsage = _performanceCounter.NextValue(); } - } - catch - { } } } diff --git a/Discord.cs b/Discord.cs index a0595155..fca55100 100644 --- a/Discord.cs +++ b/Discord.cs @@ -37,8 +37,11 @@ namespace VRCX internal void Exit() { - m_Timer.Change(-1, -1); - m_Client?.Dispose(); + lock (this) + { + m_Timer.Change(-1, -1); + m_Client?.Dispose(); + } } private void TimerCallback(object state)