By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

creating multiple instance of same thread

P: 42
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

Expand|Select|Wrap|Line Numbers
  1. public....Button_click()
  2. {
  3. Thread t2 = new Thread(new ThreadStart(DoStuff));
  4.             t2.IsBackground = true;
  5.             t2.Start();
  6. }
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.
Feb 11 '09 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 750
PRR
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.QueueUserWorkItem threads... Background thread are more efficient
Feb 11 '09 #2

P: 42
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

Expand|Select|Wrap|Line Numbers
  1. public....Button_click() 
  2. Thread t2 = new Thread(new ThreadStart(DoStuff)); 
  3.             t2.IsBackground = true; 
  4.             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

Expand|Select|Wrap|Line Numbers
  1. public....Button_click() 
  2. Thread t2 = new Thread(new ThreadStart(DoStuff)); 
  3.             t2.IsBackground = true; 
  4.             t2.Start(); 
here whn control enters into it the 1st thread terminates...

can u help me now???


i tried ThreadPool.QueueUserWorkItem as below

Expand|Select|Wrap|Line Numbers
  1. 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?
Feb 11 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.