-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change task from being canceled to waiting (#118)
- Loading branch information
1 parent
0b77809
commit 0c96718
Showing
6 changed files
with
93 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
namespace ConfusedPolarBear.Plugin.IntroSkipper; | ||
|
||
internal sealed class ScheduledTaskSemaphore : IDisposable | ||
{ | ||
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); | ||
|
||
private ScheduledTaskSemaphore() | ||
{ | ||
} | ||
|
||
public static int CurrentCount => _semaphore.CurrentCount; | ||
|
||
public static bool Wait(int timeout, CancellationToken cancellationToken) | ||
{ | ||
return _semaphore.Wait(timeout, cancellationToken); | ||
} | ||
|
||
public static int Release() | ||
{ | ||
return _semaphore.Release(); | ||
} | ||
|
||
/// <summary> | ||
/// Dispose. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <summary> | ||
/// Protected dispose. | ||
/// </summary> | ||
/// <param name="disposing">Dispose.</param> | ||
private void Dispose(bool disposing) | ||
{ | ||
if (!disposing) | ||
{ | ||
return; | ||
} | ||
|
||
_semaphore.Dispose(); | ||
} | ||
} |