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. General Programming
  3. .NET (Core and Framework)
  4. Threading in c#

Threading in c#

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpsysadminperformance
6 Posts 3 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.
  • P Offline
    P Offline
    Prabhat003
    wrote on last edited by
    #1

    I have created a C# application and used threading for creating 400 folders.And I have a picture file to pass to those 400 folders.It took an average of 30 seconds in server part and an average of 10 seconds in client part. Is it possible to accomplish the task in 1 second.And lets not care the server part and its performance. Thanx in advance.

    S 1 Reply Last reply
    0
    • P Prabhat003

      I have created a C# application and used threading for creating 400 folders.And I have a picture file to pass to those 400 folders.It took an average of 30 seconds in server part and an average of 10 seconds in client part. Is it possible to accomplish the task in 1 second.And lets not care the server part and its performance. Thanx in advance.

      S Offline
      S Offline
      Steppo
      wrote on last edited by
      #2

      First, is impossible to "not care" the server, because you write a lot of folders and pictures phisically inside the server. Dry Response -> NOT IN 1 SECOND! The times seems to be ok, but maybe is better if you post the code...

      P 1 Reply Last reply
      0
      • S Steppo

        First, is impossible to "not care" the server, because you write a lot of folders and pictures phisically inside the server. Dry Response -> NOT IN 1 SECOND! The times seems to be ok, but maybe is better if you post the code...

        P Offline
        P Offline
        Prabhat003
        wrote on last edited by
        #3

        Member 2998912,Thanx for the reply. "dont care" the server part means that it is okay if server part becomes hang also.Below is the code i used to create 400 folders and threading is also required. //Method to create folder int j=0; public void CreateFolders() { Directory.CreateDirectory(@"d:\test1\" + j ); string name = "namobuddha.jpeg"; string filename = @"d:\test1\p\namobuddha.jpeg"; Image im = Image.FromFile(filename); MemoryStream ms = new MemoryStream(); im.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); byte[] image1 = ms.ToArray(); //for the method of server part Service a1 = new Service(); a1.capture2(image1, j.ToString(), name);// method from webservice j=j+1; } public void ForThread() { Thread[] t1 = new Thread[400]; for (int i = 0; i <= 399; i++) { t1[i] = new Thread(new ThreadStart(CreateFolders)); t1[i].Start(); t1[i].Join(); } } Can there be any solution using the TimeOut property in server part or client part.

        L 1 Reply Last reply
        0
        • P Prabhat003

          Member 2998912,Thanx for the reply. "dont care" the server part means that it is okay if server part becomes hang also.Below is the code i used to create 400 folders and threading is also required. //Method to create folder int j=0; public void CreateFolders() { Directory.CreateDirectory(@"d:\test1\" + j ); string name = "namobuddha.jpeg"; string filename = @"d:\test1\p\namobuddha.jpeg"; Image im = Image.FromFile(filename); MemoryStream ms = new MemoryStream(); im.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); byte[] image1 = ms.ToArray(); //for the method of server part Service a1 = new Service(); a1.capture2(image1, j.ToString(), name);// method from webservice j=j+1; } public void ForThread() { Thread[] t1 = new Thread[400]; for (int i = 0; i <= 399; i++) { t1[i] = new Thread(new ThreadStart(CreateFolders)); t1[i].Start(); t1[i].Join(); } } Can there be any solution using the TimeOut property in server part or client part.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Prabhat003 wrote:

          t1[i].Start(); t1[i].Join();

          :confused::confused::confused: so you create and start a thread, then wait for it to finish before launching the next one? what is the purpose then of all these threads? BTW: I am not implying you should have 400 threads competing against each other at the same time; I would rather have say 2, 3 or 4 of them, each doing their part of the overall job. Furthermore, if all images are the same, there is no need to convert it 400 times from JPEG to GIF; just load it once, convert and save it once, then just copy the files. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Happy 2008!


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            Prabhat003 wrote:

            t1[i].Start(); t1[i].Join();

            :confused::confused::confused: so you create and start a thread, then wait for it to finish before launching the next one? what is the purpose then of all these threads? BTW: I am not implying you should have 400 threads competing against each other at the same time; I would rather have say 2, 3 or 4 of them, each doing their part of the overall job. Furthermore, if all images are the same, there is no need to convert it 400 times from JPEG to GIF; just load it once, convert and save it once, then just copy the files. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Happy 2008!


            P Offline
            P Offline
            Prabhat003
            wrote on last edited by
            #5

            Thank you Luc Pattyn. In client part, 400 folders can just be created in one second by using thread or without using it also.but server part can't retrieve all folders in such small time with all folders containing same image.So I have done that way.I dont know whether it is effective or not.but i ll try other ways also.Is there any efficient way that u can suggest me?Can anything be done in the server part? thank u. happy 2008.

            L 1 Reply Last reply
            0
            • P Prabhat003

              Thank you Luc Pattyn. In client part, 400 folders can just be created in one second by using thread or without using it also.but server part can't retrieve all folders in such small time with all folders containing same image.So I have done that way.I dont know whether it is effective or not.but i ll try other ways also.Is there any efficient way that u can suggest me?Can anything be done in the server part? thank u. happy 2008.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Prabhat003 wrote:

              400 folders can just be created in one second by using thread or without using it also

              :confused::confused: so you create 400 threads while you know it does not help? I repeat my suggestion: use only a couple of threads but make it so they can work at the same time (i.e. don't join immediately); you will shorten the elapsed time assuming the bottleneck is in communicating with (and/or waiting for) the server's response. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Happy 2008!


              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