Skip to content

Commit 4b5336d

Browse files
committed
Update README_CN.md
1 parent a55db09 commit 4b5336d

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README_CN.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,48 @@ long timestamp = Utils.countMilliseconds(dt);
430430
- Utils.countSeconds:计算给定时间到1970.01.01T00:00:00之间的秒数差,返回int
431431
- Utils.countMilliseconds:计算给定时间到1970.01.01T00:00:00之间的毫秒数差,返回long
432432

433-
需要注意,由于C#的DateTime和TimeSpan在精度上达不到纳秒级别,所以如果要操作纳秒精度的时间数据时,可以通过 `NanoTimestamp.getInternalValue()`来获取内部保存的long值,不要通过DateTime和TimeSpan转换,否则会造成精度损失。
433+
需要注意,由于C#的DateTime和TimeSpan在精度上达不到纳秒级别,所以如果要操作纳秒精度的时间数据时,可以通过 `NanoTimestamp.getInternalValue()`来获取内部保存的long值,不要通过DateTime和TimeSpan转换,否则会造成精度损失。
434+
435+
436+
### 9. C# 流数据 API
437+
438+
C# 程序可以通过API订阅数据流,当流数据进入客户端后,C# API处理数据的方式有两种:
439+
440+
* 客户机上的应用程序定期检查是否添加了新数据。如果添加了新数据,应用程序会获取数据并且在工作中使用它们。
441+
```
442+
PollingClient client = new PollingClient(subscribePort);
443+
TopicPoller poller1 = client.subscribe(serverIP, serverPort, tableName, offset);
444+
445+
while (true) {
446+
ArrayList<IMessage> msgs = poller1.poll(1000);
447+
448+
if (msgs.size() > 0) {
449+
BasicInt value = msgs.get(0).getValue<BasicInt>(2); //取表中第一行第二个字段
450+
}
451+
}
452+
```
453+
* C# API使用预先设定的MessageHandler直接使用新数据。
454+
455+
首先需要调用者先定义 handler , 需要实现 dolphindb.streaming.MessageHandler接口。
456+
```
457+
public class MyHandler implements MessageHandler {
458+
public void doEvent(IMessage msg) {
459+
BasicInt qty = msg.getValue<BasicInt>(2);
460+
//..处理数据
461+
}
462+
}
463+
```
464+
在启动订阅时,把handler实例作为参数传入订阅函数。
465+
466+
```
467+
ThreadedClient client = new ThreadedClient(subscribePort);
468+
469+
client.subscribe(serverIP, serverPort, tableName, new MyHandler(), offsetInt);
470+
```
471+
472+
**handler模式客户端(多线程)(ThreadPollingClient)**
473+
```
474+
ThreadPooledClient client = new ThreadPooledClient(subscribePort);
475+
476+
client.subscribe(serverIP, serverPort, tableName, new MyHandler(), offsetInt);
477+
```

0 commit comments

Comments
 (0)