Creating a Simple PLINQ Query
PLINQ-Parallel LINQ:-It is the parallel implementation of LINQ, in which a query can be executed by using multiple processors.

A simple PLIQ query works on a large collection of data. This implies that on a small collection of data, the effect of a PLINQ is not visible.



Now, we add the Default.aspx page and write the following code:

  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <center> 
    <div>
        <h1>Creating a Simple PLINQ Query</h1>
    <table>
        <tr> <td>Enter first number </td> <td> <asp:TextBox ID="txtFirstNo" runat="server"></asp:TextBox> </td> </tr>
        <tr> <td>Enter second number </td> <td> <asp:TextBox ID="txtSecondNo" runat="server"></asp:TextBox></td> </tr>
        <tr> <td>Range divided by number </td> <td><asp:TextBox ID="txtRangeNo" runat="server"></asp:TextBox> </td> </tr>
        <tr> <td> </td> <td> <asp:Button ID="btnDisplayRecord" runat="server" Text="Display Record" Font-Bold="true" OnClick="btnDisplayRecord_Click" /> </td> </tr>
    </table>
        <asp:ListBox ID="lbDetail" runat="server" Width="300px" Height="400px" Font-Bold="true"></asp:ListBox>
    </div>
            </center>
    </form>
</body>
</html>




Now, double click on Display Record button and write the following code:-

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDisplayRecord_Click(object sender, EventArgs e)
    {
        lbDetail.Items.Clear();
        int firstno, secondno, rangeno;
        firstno = Convert.ToInt32(txtFirstNo.Text);
        secondno = Convert.ToInt32(txtSecondNo.Text);
        rangeno = Convert.ToInt32(txtRangeNo.Text);

        var sourcedata = Enumerable.Range(firstno, secondno);
        var parallelQuery = from num in sourcedata.AsParallel().AsOrdered() where num % num == 0 select num;

        foreach (var data in parallelQuery)
        {
            if (data < secondno)
            {
                lbDetail.Items.Add(data.ToString());
            }
        }

    }
}



Now run the application and click on Display Record button and get output.