File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -52,19 +52,19 @@ An asynchronous queue that supports multiple threads
52
52
Create a queue:
53
53
54
54
``` csharp
55
- var asyncQueue = new AsyncQueue <FooTask >();
55
+ var asyncQueue = new AsyncQueue <FooTask >();
56
56
```
57
57
58
58
Add task to queue:
59
59
60
60
``` csharp
61
- asyncQueue .Enqueue (new FooTask ());
61
+ asyncQueue .Enqueue (new FooTask ());
62
62
```
63
63
64
64
Waiting for the task to dequeue:
65
65
66
66
``` csharp
67
- var fooTask = await asyncQueue .DequeueAsync ();
67
+ var fooTask = await asyncQueue .DequeueAsync ();
68
68
```
69
69
70
70
## Contributing
Original file line number Diff line number Diff line change @@ -38,3 +38,50 @@ PackageReference:
38
38
</PackageReference >
39
39
```
40
40
41
+ ## 使用方法
42
+
43
+ ### AsyncQueue
44
+
45
+ 高性能内存生产者消费者队列,支持多线程入队和多线程等待出队
46
+
47
+ 最简使用方法
48
+
49
+ ``` csharp
50
+ // 下面的 FooTask 是任意自定义类
51
+ var asyncQueue = new AsyncQueue <FooTask >();
52
+
53
+ // 线程1
54
+ asyncQueue .Enqueue (new FooTask ());
55
+
56
+ // 线程2
57
+ var fooTask = await asyncQueue .DequeueAsync ();
58
+ ```
59
+
60
+ 详细请看 [ dotnet 使用 AsyncQueue 创建高性能内存生产者消费者队列] ( https://blog.lindexi.com/post/dotnet-%E4%BD%BF%E7%94%A8-AsyncQueue-%E5%88%9B%E5%BB%BA%E9%AB%98%E6%80%A7%E8%83%BD%E5%86%85%E5%AD%98%E7%94%9F%E4%BA%A7%E8%80%85%E6%B6%88%E8%B4%B9%E8%80%85%E9%98%9F%E5%88%97.html )
61
+
62
+ ### DoubleBufferTask
63
+
64
+ 双缓存任务和双缓存类,支持多线程快速写入和单线程读取批量的数据,支持等待缓存执行完成
65
+
66
+ 最简使用方法
67
+
68
+ ``` csharp
69
+ var doubleBufferTask = new DoubleBufferTask <Foo >(list =>
70
+ {
71
+ // 执行批量的 List<Foo> 任务的方法
72
+ // 这个传入的委托将会在缓存有数据时被调用,每次调用的时候传入的 list 列表至少存在一个元素
73
+ });
74
+
75
+ // 其他线程调用 AddTask 方法加入任务
76
+ doubleBufferTask .AddTask (new Foo ());
77
+
78
+ // 在业务端完成之后,调用 Finish 方法表示不再有任务加入
79
+ // 此 Finish 方法非线程安全,必须业务端根据业务调用
80
+ doubleBufferTask .Finish ();
81
+
82
+ // 其他线程可以调用 WaitAllTaskFinish 等待缓存所有任务执行完成
83
+ // 在调用 Finish 方法之后,缓存的所有任务被全部执行之后将会返回
84
+ await doubleBufferTask .WaitAllTaskFinish ();
85
+ ```
86
+
87
+ 详细请看 [ dotnet 双缓存数据结构设计 下载库的文件写入缓存框架] ( https://blog.lindexi.com/post/dotnet-%E5%8F%8C%E7%BC%93%E5%AD%98%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E8%AE%BE%E8%AE%A1-%E4%B8%8B%E8%BD%BD%E5%BA%93%E7%9A%84%E6%96%87%E4%BB%B6%E5%86%99%E5%85%A5%E7%BC%93%E5%AD%98%E6%A1%86%E6%9E%B6.html )
You can’t perform that action at this time.
0 commit comments