不用找了,比较全的signalR例子已经为你准备好了.
2015-03-30 22:46
417 查看
这几天想着将一个winform的工具上线到web上,因为对时时性的要求比较高,找朋友咨询了一下推荐了SignlarR 框架,比较强大.昨天才看到,今天研究了一下将里面的例子都拿出来共享.
官方的参考:http://www.asp.net/signalr/overview/getting-started
安装SignalR: NuGet命令:
PM> Install-Package Microsoft.AspNet.SignalR
<------------1:与他人聊天:[b]------------>[/b]
后台代码示例:
View Code
注:本次实现的所谓的时时刷新数据和官方提供的Demo有很大的差异,并不是后台代码的角度来刷新,而是从前端的角度来实现的。
====>点我下载DEMO<====
官方的参考:http://www.asp.net/signalr/overview/getting-started
安装SignalR: NuGet命令:
PM> Install-Package Microsoft.AspNet.SignalR
<------------1:与他人聊天:[b]------------>[/b]
后台代码示例:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace MyReresh.ViewData { [HubName("viewDataHub")] public class ViewDataHub : Hub { [HubMethodName("refresh")] public List<Stock> Refresh() { return Stock.GetAll(); } [HubMethodName("RefreshClients")] public void RefreshClients() { Clients.All.myrefresh(Stock.GetAll()); } } public class Stock { private string opendoor; public string Opendoor { get { return opendoor; } set { opendoor = value; } } private double price; public double Price { get { return price; } set { price = value; } } private DateTime opentiem = System.DateTime.Now; public DateTime Opentiem { get { return opentiem; } set { opentiem = value; } } public static List<Stock> GetAll() { Random rand = new Random(); List<Stock> list = new List<Stock>() { new Stock{Opendoor="Door1",Price=rand.NextDouble()*100}, new Stock{Opendoor="Door2",Price=rand.NextDouble()*100}, new Stock{Opendoor="Door3",Price=rand.NextDouble()*100} }; return list; } } }
View Code
注:本次实现的所谓的时时刷新数据和官方提供的Demo有很大的差异,并不是后台代码的角度来刷新,而是从前端的角度来实现的。
====>点我下载DEMO<====
相关文章推荐
- 不用找了,比较全的signalR例子已经为你准备好了.
- 不用找了,比较全的signalR例子已经为你准备好了(2)---JqGrid 服务端刷新方式-注释详细-DEMO源码下载
- 事件代理总结: 已经有一些使用主流类库的事件代理示例出现了,比如说jQuery、Prototype以及Yahoo! UI。你也可以找到那些不用任何类库的例子,比如说Usable Type blog上的这一个。一旦需要的话,事件代理将是你工具箱里的一件得心应手的工具,而且它很容易实现。
- 比较全的signalR例子
- jsf_inaction4 例子和项目之间的比较,-css的定义
- 蓝桥杯准备已经差不多了,就在2个星期前,我还在为我的算法而担忧,现在已经差不多了
- JavaScript冒泡排序(冒泡排序最优版)包括如果原数组已经排好顺序,不需要在比较,直接终止循环!
- 多谱音乐,关于吉他谱和其他乐谱,我们已经准备了2000万首
- 不用if比较两个数大小
- 一个宏比较两个数的大小(不用>,if语句)
- socket上http协议应用(使用socket进行http通信的例子,准备好报头以后,简单read/write就可以了)
- 接口回调比较实用的例子,很好理解
- delphi 线程教学第一节:初识多线程(讲的比较浅显),还有三个例子
- jquery.validate不用submit而用js提交的例子
- iOS常用的几个基础类 一个不用xib文件的例子
- 第三章SignalR在线聊天例子
- ASP中使用事务的例子。已经测试通过。
- 已经比较简单的日志分割脚本
- 一个比较实用的jQuery例子
- 一个比较有意思的判断两数大小的方法,不用逻辑比较运算符