FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TCSystemCS/Thread/AsyncUpdateHelper.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
/
AsyncUpdateHelper.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (54 loc) · 2.03 KB
Breadcrumbs
TCSystemCS
/
Thread
/
AsyncUpdateHelper.cs
Copy path
File metadata and controls
71 lines (54 loc) · 2.03 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// *******************************************************************************
//
// ******* *** *** *
// * * * *
// * * * *****
// * * *** * * ** * ** ***
// * * * * * * * **** * * *
// * * * * * * * * * * *
// * *** *** * ** ** ** * *
// *
// *******************************************************************************
// 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
.
Threading
;
using
System
.
Threading
.
Tasks
;
#endregion
namespace
TCSystem
.
Thread
;
internal
sealed
class
AsyncUpdateHelper
:
IAsyncUpdateHelper
{
#region Public
public
async
Task
BeginUpdateAsync
(
)
{
Interlocked
.
Increment
(
ref
_numPendingStops
)
;
Interlocked
.
Increment
(
ref
_numPendingUpdates
)
;
await
_semaphore
.
WaitAsync
(
)
;
Interlocked
.
Decrement
(
ref
_numPendingStops
)
;
Interlocked
.
Decrement
(
ref
_numPendingUpdates
)
;
}
public
async
Task
WaitAsync
(
)
{
Interlocked
.
Increment
(
ref
_numPendingUpdates
)
;
await
_semaphore
.
WaitAsync
(
)
;
Interlocked
.
Decrement
(
ref
_numPendingUpdates
)
;
}
public
void
EndUpdate
(
)
{
_semaphore
.
Release
(
)
;
}
public
bool
ShouldStop
=>
Interlocked
.
Read
(
ref
_numPendingStops
)
>
0
;
public
bool
IsUpdatePending
=>
Interlocked
.
Read
(
ref
_numPendingUpdates
)
>
0
;
#endregion
#region Private
private
long
_numPendingStops
;
private
long
_numPendingUpdates
;
private
readonly
SemaphoreSlim
_semaphore
=
new
(
1
,
1
)
;
#endregion
}
Back
|
FazBrowse Home
|
New Git URL