feat: 处理系统恢复以重置媒体检测
This commit is contained in:
@@ -57,6 +57,18 @@ namespace TimerApp
|
||||
return Volatile.Read(ref _mediaPlaying);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制失效媒体播放状态缓存
|
||||
/// </summary>
|
||||
public static void InvalidateMediaCache()
|
||||
{
|
||||
Interlocked.Exchange(ref _mediaLastUpdateMs, -1);
|
||||
// 不直接重置 _mediaPlaying,以免在检测过程中出现闪烁,
|
||||
// 只是强制下一次 IsMediaPlaying 触发新的检测。
|
||||
// 但如果处于 Resume 状态,假设不播放是安全的。
|
||||
Volatile.Write(ref _mediaPlaying, false);
|
||||
}
|
||||
|
||||
private static bool _mediaPlaying;
|
||||
private static long _mediaLastUpdateMs = -1;
|
||||
private static int _mediaUpdateInProgress;
|
||||
@@ -256,7 +268,12 @@ namespace TimerApp
|
||||
thread.IsBackground = true;
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
// Wait with timeout (e.g. 2 seconds) to prevent hanging
|
||||
if (!thread.Join(2000))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (error is not null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user