How to Check Proxies Using .NET C#?

Well below is my code but doesnt seems to work.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public async Task PerformStartChecking(int Bots, List<Proxy> ProxyCollection)
{
var semaphore = new SemaphoreSlim(Bots);
foreach (var proxy in ProxyCollection)
{
await semaphore.WaitAsync();
_ = Task.Run(async () =>
{
try
{
var handler = new HttpClientHandler
{
Proxy = new WebProxy($"http://{proxy.HostIP}:{proxy.Port}"),
UseProxy = true
};
using (var client = new HttpClient(handler))
{
var response = await client.GetAsync("http://www.google.com");
if (response.IsSuccessStatusCode)
{
MessageBox.Show("Good");
}
else
{
MessageBox.Show("Error");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"{ex}");
}
finally
{
semaphore.Release();
}
});
}
}
</code>
<code>public async Task PerformStartChecking(int Bots, List<Proxy> ProxyCollection) { var semaphore = new SemaphoreSlim(Bots); foreach (var proxy in ProxyCollection) { await semaphore.WaitAsync(); _ = Task.Run(async () => { try { var handler = new HttpClientHandler { Proxy = new WebProxy($"http://{proxy.HostIP}:{proxy.Port}"), UseProxy = true }; using (var client = new HttpClient(handler)) { var response = await client.GetAsync("http://www.google.com"); if (response.IsSuccessStatusCode) { MessageBox.Show("Good"); } else { MessageBox.Show("Error"); } } } catch (Exception ex) { MessageBox.Show($"{ex}"); } finally { semaphore.Release(); } }); } } </code>
public async Task PerformStartChecking(int Bots, List<Proxy> ProxyCollection)
{
    var semaphore = new SemaphoreSlim(Bots);

    foreach (var proxy in ProxyCollection)
    {
        await semaphore.WaitAsync();

        _ = Task.Run(async () =>
        {
            try
            {
                var handler = new HttpClientHandler
                {
                    Proxy = new WebProxy($"http://{proxy.HostIP}:{proxy.Port}"),
                    UseProxy = true
                };

                using (var client = new HttpClient(handler))
                {
                    var response = await client.GetAsync("http://www.google.com");

                    if (response.IsSuccessStatusCode)
                    {
                        MessageBox.Show("Good");
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex}");
            }
            finally
            {
                semaphore.Release();
            }
        });
    }
}

Ok i dont know why it doesnt work but i got an exception saying this ( i think its a timeout error ) —>;

System.Threading.Tasks.TaskCanceledException: The request was
canceled due to the configured HttpClient.Timeout of 100 seconds
elapsing.
— > System.TimeoutException: The operation was canceled.
— > System.Threading.Tasks.TaskCanceledException: The operation
was canceled.
— > System.IO.IOException: Unable to read data from the transport
connection: The I/O operation has been aborted because of either a
thread exit or an application request ..
— > System.Net.Sockets.SocketException (995): The I/O operation has
been aborted because of either a thread exit or an application request.
— End of inner exception stack trace —
at
System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowExcep
tion(SocketError error, CancellationToken cancellationToken)
at
System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Thre
ading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16
token)
at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage
request, Boolean async, CancellationToken cancellationToken)
— End of inner exception stack trace —
at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage
request, Boolean async, CancellationToken cancellationToken)
at
System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRe
tryAsync(HttpRequestMessage request, Boolean async, Boolean
doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage
request, Boolean async, CancellationToken cancellationToken)
at
System.Net.Http.HttpClient .< SendAsync>g_Core|83_0(HttpRequestMes
sage request, HttpCompletionOption completionOption,
CancellationTokenSource cts, Boolean disposeCts,
CancellationTokenSource pendingRequestsCts, CancellationToken
originalCancellationToken)
— End of inner exception stack trace —
— End of inner exception stack trace —
at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean
telemetryStarted, HttpResponseMessage response,
CancellationTokenSource cts, CancellationToken cancellationToken,
CancellationTokenSource pendingRequestsCts)
at
System.Net.Http.HttpClient .< SendAsync>g_Core|83_0(HttpRequestMes
sage request, HttpCompletionOption completionOption,
CancellationTokenSource cts, Boolean disposeCts,
CancellationTokenSource pendingRequestsCts, CancellationToken
originalCancellationToken)
at

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật