Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am implementing threading in my project.
I am doing something like this.
This is my worker class:
C#
public class test
{
public test(){};
public void DoWork(string abc)
{
bool result = false;
try
{
//do some work
result = true;
}
catch(){}
return result;
}
}


This is my threaing class:
C#
public class threading
{
test objTest = null;
public threading()
{
objTest = new objTest();
}

public void ThreadCall()
{
Thread myThread = new Thread(new ParameterizedThreadStart(objTest.DoWork));
myThread.Start("abc");
}
}


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.

Thanks,
Nagendra.
Posted
Updated 20-Oct-11 0:12am
v2

Use BackgroundWorker if you want feedback form your thread, it's easier and has all the parts ready for you to use.
 
Share this answer
 
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,
C#
BackgroundWorker
is a nice handy thing.

Hope this helps

Cheers
 
Share this answer
 
Comments
Mehdi Gholam 20-Oct-11 6:47am    
My 5!
I.explore.code 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900