wcf - 使用 WCF 服务自动向客户端发送值
问题描述
我有一个向 WPF 应用程序提供数据的服务,其中一个数据是一个名为 Market Price 的值,例如我希望它每分钟更新一次(我只是在做一个模拟,所以该服务将返回一个随机值)。所以我想知道最好和最简单的方法。
解决方案
您可以尝试使用DispatcherTimer类。
在构造函数类上声明 this 并根据需要设置间隔:
var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);//method to be executed
dispatcherTimer.Interval = new TimeSpan(0,0,1);//the interval is set to 1 second
dispatcherTimer.Start();
并声明一个要执行的方法:
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
//call WCF service and update the value
}
推荐阅读
- ios - View Debug 中的 Collection View Frame 与代码不同
- java - 如何在firebase中比较来自不同UID的积分
- javascript - 如何为对象编写全局 get+set 方法
- javascript - 当使用流星在科尔多瓦应用程序中发生网络变化时在服务器之间动态切换
- javascript - WDS(Webpack 开发服务器)在 VUEJS 中断开连接
- gitlab - Gitlab中的用户分组
- java - 如果我弄乱了登录,它将直接进入 else 条件,如果我正确登录,它将进入两个条件
- big-o - 这个算法的复杂度是否正确?
- php - Facebook Graph 未按顺序返回结果
- c++ - if/else 遇到问题