Click here to Skip to main content
11,933,180 members (63,875 online)
Rate this:
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 20-Oct-11 6:47am
My 5!
gladiatron 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.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