FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TCSystemCS/Thread/SemaphoreSlimExt.cs at develop · tgoessler/TCSystemCS · GitHub
tgoessler
TCSystemCS
Repository navigation
Code
Pull requests
6
(6)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
TCSystemCS
/
Thread
/
SemaphoreSlimExt.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (43 loc) · 1.77 KB
Breadcrumbs
TCSystemCS
/
Thread
/
SemaphoreSlimExt.cs
Copy path
File metadata and controls
51 lines (43 loc) · 1.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// *******************************************************************************
//
// ******* *** *** *
// * * * *
// * * * *****
// * * *** * * ** * ** ***
// * * * * * * * **** * * *
// * * * * * * * * * * *
// * *** *** * ** ** ** * *
// *
// *******************************************************************************
// see https://github.com/tgoessler/TCSystemCS for details.
// Copyright (C) 2003 - 2026 Thomas Goessler. All Rights Reserved.
// *******************************************************************************
//
// TCSystem is the legal property of its developers.
// Please refer to the COPYRIGHT file distributed with this source distribution.
//
// *******************************************************************************
#region Usings
using
System
;
using
System
.
Threading
;
using
System
.
Threading
.
Tasks
;
#endregion
namespace
TCSystem
.
Thread
;
/// <summary>Provides disposable lock scopes for <see cref="SemaphoreSlim" />.</summary>
public
static
class
SemaphoreSlimExt
{
#region Public
/// <summary>Waits for the semaphore and returns a scope that releases it when disposed.</summary>
public
static
IDisposable
Lock
(
this
SemaphoreSlim
semaphore
)
{
semaphore
.
Wait
(
)
;
return
new
SemaphoreSlimLock
(
semaphore
)
;
}
/// <summary>Asynchronously waits for the semaphore and returns a scope that releases it when disposed.</summary>
public
static
async
Task
<
IDisposable
>
LockAsync
(
this
SemaphoreSlim
semaphore
)
{
await
semaphore
.
WaitAsync
(
)
;
return
new
SemaphoreSlimLock
(
semaphore
)
;
}
#endregion
}
Back
|
FazBrowse Home
|
New Git URL