示例#1
0
        /// <summary>
        /// Try connecting to <paramref name="ep"/> and invokes <code>OnResult</code> event if success.
        /// </summary>
        protected async void Scan(IPEndPoint ep)
        {
            try
            {
                using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    client.BeginConnect(ep, null, null);
                    await Task.Delay(Timeout, TokenSource.Token).ConfigureAwait(false);

                    if (client.Connected)
                    {
                        OnResult?.BeginInvoke(this, ep, null, null);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                SemaphoreParallelism.Release();
            }
        }