creating multiple instance of same thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • libish
    New Member
    • Oct 2008
    • 42

    creating multiple instance of same thread

    hi all,
    can any one help me to create multiple instance of a thread?
    here what i'm doing is that , i want to upload a file from my c# windows application, once i put it for upload i want to continue uploading another, so and so
    here what i did is on each button click i created a thread that handles the file uploading

    Code:
    public....Button_click()
    {
    Thread t2 = new Thread(new ThreadStart(DoStuff));
                t2.IsBackground = true;
                t2.Start();
    }
    if it is for once it works fine, but if i try to upload another file using the same procedure it makes my 1st thread to stop.
    i kno this is not the way to do this stuff, please some one help.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Can you explain more ? what error are you getting? in my opinion it should not make the thread stop... unless there is some exception thrown... in that case the thread will abort .... If you are trying to access the same file then i guess you may get access denied error ...
    For short background task you can always use ThreadPool.Queu eUserWorkItem threads... Background thread are more efficient

    Comment

    • libish
      New Member
      • Oct 2008
      • 42

      #3
      here i have a form which browses a file, and after browsing i need to upload this file to an ftp server, here once i selected the file and click upload the action i written is like this

      Code:
      public....Button_click() 
      { 
      Thread t2 = new Thread(new ThreadStart(DoStuff)); 
                  t2.IsBackground = true; 
                  t2.Start(); 
      }
      here do stuff method will handle the upload fn.
      and nw i went to browse another file, and then i click upload, so the control once again gets into the method above

      Code:
      public....Button_click() 
      { 
      Thread t2 = new Thread(new ThreadStart(DoStuff)); 
                  t2.IsBackground = true; 
                  t2.Start(); 
      }
      here whn control enters into it the 1st thread terminates...

      can u help me now???


      i tried ThreadPool.Queu eUserWorkItem as below

      Code:
      bool ab = ThreadPool.QueueUserWorkItem(new WaitCallback((DoStuff)));
      still the same probblm exist

      can u suggest me a way out.
      i think itz because of the way i'm using the methods... can u help me nw?

      Comment

      Working...