我使用下面的代码来使用服务参考:
var myService = new MyService.MyServiceClient();
myService.DeleteOCDFCompleted += MyServiceDeleteOCDFComplete;
myService.DeleteOCDF(OCDF.OcdfId);
void MyServiceDeleteOCDFComplete(object sender, MyService.DeleteOCDFCompletedEventArgs e)
{
// OCDFList.Remote(**ocdf that deleted**);
MessageBox.Show("Delete Completed successfully.");
}
我想从列表中删除已删除的对象,但如何确定MyServiceDeleteOCDFComplete
函数中已删除的参数。
换句话说:如何将额外参数发送到服务引用事件。
提前感谢。
答案 0 :(得分:3)
您可以使用DeleteOCDF
方法的附加参数(称为userState
)。该参数可以是任何对象,它将在UserState
属性中传递给事件处理程序。
var myService = new MyService.MyServiceClient();
myService.DeleteOCDFCompleted += MyServiceDeleteOCDFComplete;
myService.DeleteOCDF(OCDF.OcdfId, OCDF.OcdfId);
void MyServiceDeleteOCDFComplete(object sender, MyService.DeleteOCDFCompletedEventArgs e)
{
int ocdfId = (int)e.UserState;
MessageBox.Show("Delete Completed successfully.");
}