Simple example to write PLINQ Query in C# and VB.Net

C#
using System.Net.NetworkInformation;
————————————————-
VB.Net
Imports System.Net.NetworkInformation
—————————————————-
C#
List<string> sites = new List<string>
{
“www.orhanturk.com.tr”,
“www.google.com”,
“www.yahoo.com”
};
List<PingReply> pingReplies = (from site in sites.AsParallel().WithDegreeOfParallelism(sites.Count)
                           select DoPing(site)).ToList() as List<PingReply>;
foreach (var s in pingReplies.ToList())
{
    Response.Write(s.Address + “: ” + s.RoundtripTime + “: ” + s.Status + “<br />”);
}
————————————————————————————–
VB.Net
Dim sites As New List(Of String)
sites.Add(“www.orhanturk.com.tr”)
sites.Add(“www.google.com”)
sites.Add(“www.yahoo.com”)
Dim pingReplies As List(Of PingReply) = TryCast((
                  From site In sites.AsParallel().WithDegreeOfParallelism(sites.Count) _
                  Select DoPing(site)).ToList(), List(Of PingReply))
For Each s In pingReplies.ToList()
    Response.Write(Convert.ToString(s.Address) & “: ” & Convert.ToString(s.RoundtripTime) & “: ” & Convert.ToString(s.Status) & “<br />”)
Next
—————————————————————————————-
C#
private PingReply DoPing(string site)
{
    Ping p = new Ping();
    return p.Send(site);
}
 
VB.Net
Private Function DoPing(ByVal site As String) As PingReply
    Dim p As New Ping()
    Return p.Send(site)
End Function

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

three × three =

This site uses Akismet to reduce spam. Learn how your comment data is processed.