1

我希望你能帮助我解决以下问题:

我有一个 WebService 方法,它应该返回一个 CompensationPlanReturnReturn 对象数组。该方法是这样调用的:

//This is the object I need to instanciate  because it contains the method I wanna call
CompensationPlan_Out_SyncService test = new CompensationPlan_Out_SyncService();
//This is the method that is supposed to return me an array of CompensationPlanReturnReturn objects
//The data.ToArray() is the parameter the method need, then I pass the method that I wanna run when the method finishes and I dont know what to pass as the final parameter
test.BeginCompensationPlan_Out_Sync(data.ToArray(), new AsyncCallback(complete), null)

//The method description is:
public System.IAsyncResult BeginCompensationPlan_Out_Sync(CompensationPlanDataCompensationPlan[] CompensationPlanRequest, System.AsyncCallback callback, object asyncState)

//On this method I'd like to access to the resuls (the array of CompensationPlanReturnReturn) but I dont know how
private void complete(IAsyncResult result)
    {            
        lblStatus.Text = "Complete";
    }
4

3 回答 3

4

您需要调用test.EndCompensationPlan_Out_Sync(result),它将返回异步操作的结果,或者如果发生错误则抛出异常。

于 2013-08-15T14:54:31.607 回答
2

异步方法分为两个子方法 -BeginEnd.

您需要调用EndCompensationPlan_Out_Sync以获取方法返回的实际结果 -

private void complete(IAsyncResult result)
{            
    var actualResult = test.EndCompensationPlan_Out_Sync(result);
    lblStatus.Text = "Complete";
}
于 2013-08-15T14:55:35.703 回答
0

尝试使用 AsyncState-Property 并将其转换为给定的类型。

像这样:

cSACommand = (SACommand)Result.AsyncState;
于 2013-08-15T14:54:22.977 回答