Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. parallel programming

parallel programming

Scheduled Pinned Locked Moved ASP.NET
csharpvisual-studiolinqdesignsecurity
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vasanth2vasu
    wrote on last edited by
    #1

    I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?

    R L M 4 Replies Last reply
    0
    • V vasanth2vasu

      I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?

      R Offline
      R Offline
      Rockstar_
      wrote on last edited by
      #2

      Can u plz describe ur problem? Not understood.... What is Parallel processing?

      1 Reply Last reply
      0
      • V vasanth2vasu

        I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?

        R Offline
        R Offline
        Rockstar_
        wrote on last edited by
        #3

        What u want to do actually?

        1 Reply Last reply
        0
        • V vasanth2vasu

          I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          As far as I can see there is only one insert command in the above, so how can that be made parallel (or more likely multi-threaded)?

          Use the best guess

          V 1 Reply Last reply
          0
          • L Lost User

            As far as I can see there is only one insert command in the above, so how can that be made parallel (or more likely multi-threaded)?

            Use the best guess

            V Offline
            V Offline
            vasanth2vasu
            wrote on last edited by
            #5

            supposing if there are 2 updates taking place simultaneously the updates takes some time.so to avoid the time delay i need to do it using parallel programming or threading. My main aim is to reduce the CPU work usage.

            L 1 Reply Last reply
            0
            • V vasanth2vasu

              supposing if there are 2 updates taking place simultaneously the updates takes some time.so to avoid the time delay i need to do it using parallel programming or threading. My main aim is to reduce the CPU work usage.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              vasanth2vasu wrote:

              My main aim is to reduce the CPU work usage.

              You do realise that multi-threading actually increases it? And how can you tell when there are two updates in progress since the initiator is the user pressing a button? Your question and your code sample do not make clear exactly what you are trying to achieve, but if all you want to do is to multi-thread some processes, then you should look at the Thread class[^].

              Use the best guess

              V 1 Reply Last reply
              0
              • L Lost User

                vasanth2vasu wrote:

                My main aim is to reduce the CPU work usage.

                You do realise that multi-threading actually increases it? And how can you tell when there are two updates in progress since the initiator is the user pressing a button? Your question and your code sample do not make clear exactly what you are trying to achieve, but if all you want to do is to multi-thread some processes, then you should look at the Thread class[^].

                Use the best guess

                V Offline
                V Offline
                vasanth2vasu
                wrote on last edited by
                #7

                Can yu give an example in web application where we use parallel processing for inserting and updating SQL database by C#.net simultaneously.

                L 1 Reply Last reply
                0
                • V vasanth2vasu

                  Can yu give an example in web application where we use parallel processing for inserting and updating SQL database by C#.net simultaneously.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Sorry I have not got one, but all you need to do is look at that link I gave you and code yourself some threads. You can also find lots of samples via Google, or in the CodeProject articles section..

                  Use the best guess

                  1 Reply Last reply
                  0
                  • V vasanth2vasu

                    I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?

                    M Offline
                    M Offline
                    MichaeltCheong
                    wrote on last edited by
                    #9

                    Quote:

                    string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); string strddl; SqlCommand cmdddl;

                    Quote:

                    try { conn.Open(); strddl = "INSERT INTO Users (Username,Name,UserID,Password,UserRoles,SecurityAns) VALUES(@user,@name,@id,@pass,@roles,@Sec)"; cmdddl = new SqlCommand(strddl, conn); cmdddl.Parameters.AddWithValue("@user", TextBox1.Text); cmdddl.Parameters.AddWithValue("@name", TextBox2.Text); cmdddl.Parameters.AddWithValue("@id", CID); cmdddl.Parameters.AddWithValue("@pass", Password.Text); cmdddl.Parameters.AddWithValue("@roles", Role); cmdddl.Parameters.AddWithValue("@Sec", TextBox6.Text); cmdddl.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { Response.Redirect("~/ErrorPage.aspx"); }

                    Dun't know this code may help on u or not, for the parallel processing is mean wht? i just a newbie :-D

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups