How can thread retruns a value?
-
m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?
-
m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?
You should use BackgroundWorker Component added in the version 2.0! this will solve your purpose! :)
-
You should use BackgroundWorker Component added in the version 2.0! this will solve your purpose! :)
-
private void btnStart_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
[..do some work..]// When done, return the value. e.Result = "Hello world from backgroundworker";
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Here you get the returnvalue from the thread, and you
// can use it in your Form1-thread :)
string returnValue = (string)e.Result;
}--edited, typo--
I are troll :)
-
m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?
Or you may asynchronously invoke your method by using delegates. here is a sample[^] Calin