Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
Hi All,
I am implementing threading in my project.
I am doing something like this.
This is my worker class:
public class test
public test(){};
public void DoWork(string abc)
bool result = false;
//do some work
result = true;
return result;
This is my threaing class:
public class threading
test objTest = null;
public threading()
objTest = new objTest();
public void ThreadCall()
Thread myThread = new Thread(new ParameterizedThreadStart(objTest.DoWork));
This is just a sample, my DoWork method will run for many threads.
Now i want to know is there any way available by which i can return a bool value from DoWork method after completion of thread.
Can we return a value from a method which is running under a thread because i didn't saw Thread.Start() method returning anything, if yes then how can we fetch that value.
Posted 20-Oct-11 1:11am
Edited 20-Oct-11 1:12am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use BackgroundWorker if you want feedback form your thread, it's easier and has all the parts ready for you to use.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Or, if you would still insist on using Threads for this purpose, you would have to have a shared data structure of some kind and make sure that with multiple threads running and using the same data, you synchronise them properly.
Found this one that explains quite nicely : C# Worker Thread Starter Kit[^]
Otherwise, as Mehdi already pointed out,
is a nice handy thing.
Hope this helps
Mehdi Gholam at 20-Oct-11 6:47am
My 5!
gladiatron at 20-Oct-11 10:52am
thanks mate!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 235
3 Afzaal Ahmad Zeeshan 209
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175

Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 20 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100