Click here to Skip to main content
11,805,035 members (60,738 online)
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 0:11am
Edited 20-Oct-11 0: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 315
1 Richard Deeming 200
2 Sergey Alexandrovich Kryukov 168
3 CPallini 160
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 20 Oct 2011
Copyright © CodeProject, 1999-2015
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