基本信息
源码名称:wcf 异步通知事件 示例源码
源码大小:0.10M
文件格式:.zip
开发语言:C#
更新时间:2014-03-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
有服务器端和客户端 的完整源码


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;

namespace Server
{
    public class MyServer : IServer, IDisposable
    {
        private ICallback icb;
        private Timer timer = null;//计时器,定时干活
        Random rand = null;//生成随机整数

        public void CallServerOp()
        {
            this.icb = OperationContext.Current.GetCallbackChannel<ICallback>();
            rand = new Random();
            // 生成随整数,并回调到客户端
            // 每隔3秒生成一次
            timer = new Timer((obj) => icb.CallClient(rand.Next()), null, 10, 3000);
        }

        public void Dispose()
        {
            timer.Dispose();
            Console.WriteLine("{0} - 服务实例已释放。", DateTime.Now.ToLongTimeString());
        }


        public void End()  //结束
        {
            Console.WriteLine("会话即将结束。");
        }
    }
}