处理没有正确计时

时间:2012-05-30 14:36:05

标签: c# .net wcf

我正在为我们的程序构建IP扫描程序。它目前有效,但运行速度极慢。超时似乎无法正常工作。代码如下所示:

    public Tracker Discover(Uri hostUri, string organizationTrackerId)
    {
        var binding = new NetTcpBinding();
        binding.ReceiveTimeout = TimeSpan.FromSeconds(2);
        binding.SendTimeout = TimeSpan.FromSeconds(2);
        binding.OpenTimeout = TimeSpan.FromSeconds(2);
        var endpointAddress = new EndpointAddress(hostUri);
        using (var factory = new ChannelFactory<ITrackerService>(binding, endpointAddress))
        {
            try
            {
                factory.Open(TimeSpan.FromSeconds(2));
                var channel = factory.CreateChannel();
                Tracker tracker = channel.Discover(organizationTrackerId);
                factory.Close();
                return tracker;
            }
            catch (Exception)
            {
                factory.Abort();
            }
        }
        return null;
    }

此代码从for循环中调用,循环遍历255个IP。调用此函数时,即使我尝试将超时设置为2,目前也需要大约16秒才能完成。任何想法?

0 个答案:

没有答案