Exemplo n.º 1
0
        protected List <TMessage> EndSendMessageParallel <TMessage>(IAsyncResult ar)
            where TMessage : DnsMessageBase, new()
        {
            DnsClientParallelAsyncState <TMessage> state = (DnsClientParallelAsyncState <TMessage>)ar;

            return(state.Responses);
        }
Exemplo n.º 2
0
        protected IAsyncResult BeginSendMessageParallel <TMessage>(TMessage message, AsyncCallback requestCallback, object state)
            where TMessage : DnsMessageBase, new()
        {
            List <DnsClientEndpointInfo> endpointInfos = GetEndpointInfos <TMessage>();

            DnsClientParallelAsyncState <TMessage> asyncResult =
                new DnsClientParallelAsyncState <TMessage>
            {
                UserCallback       = requestCallback,
                AsyncState         = state,
                Responses          = new List <TMessage>(),
                ResponsesToReceive = endpointInfos.Count
            };

            foreach (var endpointInfo in endpointInfos)
            {
                DnsClientParallelState <TMessage> parallelState = new DnsClientParallelState <TMessage> {
                    ParallelMessageAsyncState = asyncResult
                };

                lock (parallelState.Lock)
                {
                    parallelState.SingleMessageAsyncResult = BeginSendMessage(message, new List <DnsClientEndpointInfo> {
                        endpointInfo
                    }, SendMessageFinished <TMessage>, parallelState);
                }
            }
            return(asyncResult);
        }