WPS RTD C#实现例子
时间: 2023-07-12 08:23:21 浏览: 260
C#调用WPS2016方法和常见问题处理代码
3星 · 编辑精心推荐
以下是 WPS RTD C# 实现的示例代码:
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
namespace WPSRTDExample
{
[ComVisible(true)]
public class WPSRTD : IRtdServer
{
private IRTDUpdateEvent _callback;
private Dictionary<int, string> _topics = new Dictionary<int, string>();
private Random _random = new Random();
public int ServerStart(IRTDUpdateEvent CallbackObject)
{
_callback = CallbackObject;
return 1;
}
public void ServerTerminate()
{
_callback = null;
}
public object ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
{
if (!_topics.ContainsKey(TopicID))
{
_topics.Add(TopicID, Strings.GetValue(0).ToString());
}
return _random.Next(100);
}
public void DisconnectData(int TopicID)
{
if (_topics.ContainsKey(TopicID))
{
_topics.Remove(TopicID);
}
}
public int Heartbeat()
{
return 1;
}
public Array RefreshData(ref int TopicCount)
{
if (_callback != null)
{
_callback.UpdateNotify();
}
TopicCount = _topics.Count;
return Enumerable.Range(0, TopicCount).Select(i => _random.Next(100)).ToArray();
}
public int RefreshData(int TopicID, ref Array NewValues, ref bool GetNewValues)
{
NewValues.SetValue(_random.Next(100), 0);
return 1;
}
public object[,] GetLastUpdate(ref int TopicCount)
{
TopicCount = _topics.Count;
return Enumerable.Range(0, TopicCount).Select(i => new object[] { _topics.ElementAt(i).Value, _random.Next(100) }).ToArray();
}
}
}
```
在这个示例中,WPS RTD 服务器会返回一个随机整数,当连接数据时。在刷新数据时,它会向每个主题返回一个新的随机整数。在获取最近更新时,它将返回每个主题的名称和最后一个随机整数。你可以根据你的需求修改这个示例代码。
阅读全文