File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 3
3
using System . Collections . Generic ;
4
4
using System . Threading . Tasks ;
5
5
6
+ #if NETFRAMEWORK
7
+ using ValueTask = System . Threading . Tasks . Task ;
8
+ #endif
9
+
6
10
namespace dotnetCampus . Threading
7
11
{
8
12
/// <summary>
9
13
/// 双缓存任务
10
14
/// </summary>
11
- public class DoubleBufferTask < T , TU > where T : class , ICollection < TU >
15
+ public class DoubleBufferTask < T , TU > : IAsyncDisposable
16
+ where T : class , ICollection < TU >
12
17
{
13
18
/// <summary>
14
19
/// 创建双缓存任务,执行任务的方法放在 <paramref name="doTask"/> 方法
@@ -92,5 +97,12 @@ public Task WaitAllTaskFinish()
92
97
private readonly Func < T , Task > _doTask ;
93
98
94
99
private DoubleBuffer < T , TU > DoubleBuffer { get ; }
100
+
101
+ /// <inheritdoc />
102
+ public async ValueTask DisposeAsync ( )
103
+ {
104
+ Finish ( ) ;
105
+ await WaitAllTaskFinish ( ) ;
106
+ }
95
107
}
96
108
}
Original file line number Diff line number Diff line change 4
4
using System . Text ;
5
5
using System . Threading . Tasks ;
6
6
7
+ #if NETFRAMEWORK
8
+ using ValueTask = System . Threading . Tasks . Task ;
9
+ #endif
10
+
7
11
namespace dotnetCampus . Threading
8
12
{
9
13
// 这个接口在 .NET Framework 4.5 没有
10
14
interface IAsyncDisposable
11
15
{
16
+ ValueTask DisposeAsync ( ) ;
12
17
}
13
18
}
You can’t perform that action at this time.
0 commit comments