遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

WCF,心跳检测

文章地址:http://www.cnblogs.com/huangxincheng/archive/2011/11/13/2246934.html#2256396

System.Timers.Timer是基于.Net PoolThread实现的,独立于UI线程

        public void GetService(string address)
        {
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Elapsed += (obj, sender) =>
            {
                try
                {
                    //这个是定时的检测IIS是否挂掉
                    var factory = new ChannelFactory<IServiceList>(new NetTcpBinding(SecurityMode.None),
                                                                   new EndpointAddress(address));

                    factory.CreateChannel().AddSearchList(search);

                    factory.Close();

                    timer.Interval = 10000;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            };
            timer.Start();
        }

 

posted on 2011-11-29 16:02  遗忘海岸  阅读(1264)  评论(0编辑  收藏  举报