后台工人返回值?

时间:2014-08-06 03:34:47

标签: c# backgroundworker

private float bw_DoWork(object sender, DoWorkEventArgs e)

我试图让线程方法返回一个值,但我得到了

Assets/Scripts/test.cs(574,71): error CS0407: A method or delegate float test.bw_DoWork(object, System.ComponentModel.DoWorkEventArgs)' return type does not match delegate `void System.ComponentModel.DoWorkEventHandler(object, System.ComponentModel.DoWorkEventArgs)' return type

是做什么的?

1 个答案:

答案 0 :(得分:0)

This should do the trick. Keep in mind you will need to return your values differently you cannot return in a thread. The best way is to Invoke inside a separate thread.

private string  ReturnObject {get;set;}
DoWork(){

UpdateValues("My Value");
}     

UpdateValues(string _value){
MethodInvoker action = delegate
                {
                   //Controls Mehtods HERE
ReturnObject = _value;
                };

     this.Invoke(action)
}