本文介绍了如何在Silverlight中等待异步方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在wcf服务中创建了两个函数,并在Silverlight中使用异步方法进行调用,在一个方法之后但在第一个方法完成之前,请一个方法执行Silverlight执行第二个方法.我希望第一个方法完全执行,然后第二个方法调用.请帮忙.
I am make two function in wcf service and call in silverlight using asynchronization method call one method after one method but before completion of first method silverlight execute the 2nd method. I want first method completely execute then second method call. Please help its urgent.
private GDOperations.GDDoneOperationsClient _gdDoneOperation; private ImageOperationsClient proxy = null; foreach (var file in _filesCollection) { clsImageTransactionEntity _clsImageEntity = new clsImageTransactionEntity(); _clsImageEntity.ImageByte = GetFileData(file.OpenRead()); _clsImageEntity.ImageExtension = file.Extension; _clsImageEntity.ImageName = file.Name; _clsImageEntity.ImageType = 2; _clsImageEntity.ImagePath = "~/CMSImages/FinalImages/" + lblSelectedBarcode.Content.ToString() + "/" + file.Name; _clsImageEntity.JabongBarcode = lblSelectedBarcode.Content.ToString(); GDOperations.clsImageTransactionEntity _clsImageGDEntity = new GDOperations.clsImageTransactionEntity(); _clsImageGDEntity.ImageExtension = file.Extension; _clsImageGDEntity.ImageName = file.Name; _clsImageGDEntity.ImageType = 2; _clsImageGDEntity.ImagePath = "~/CMSImages/FinalImages/" + lblSelectedBarcode.Content.ToString() + "/" + file.Name; _clsImageGDEntity.JabongBarcode = lblSelectedBarcode.Content.ToString(); _clsImageGDEntity.RoleId = roleID; _clsImageGDEntity.TaskID = taskID; _clsImageGDEntity.UserID = UserId; _clsImageGDEntity.SystemIP = systemIP; _clsGdAllotment.clsImageTransactionEntity.Add(_clsImageGDEntity); //----- first method calling----- proxy.UploadFinalImageCompleted += (s, e) => { if (e.Error == null) { } }; proxy.UploadFinalImageAsync(_clsImageEntity); countfile = countfile + 1; pbUploadFiles.Value = countfile; } _clsGdAllotment.GdID = int.Parse(lblUserID.Content.ToString()); _clsGdAllotment.JabongBarcode = lblSelectedBarcode.Content.ToString(); _clsGdAllotment.TaskID = taskID; //--- after for loop completion calling second method ----- _gdDoneOperation.InsertGDDoneInformationCompleted += _gdDoneOperation_InsertGDDoneInformationCompleted; _gdDoneOperation.InsertGDDoneInformationAsync(_clsGdAllotment);谢谢&关于Ram Kumar
Thanks & Regards Ram Kumar
推荐答案在第一个的完成处理程序中调用第二个方法.在调用第二个方法之前,请确保您的第一个异步回调成功返回. /ravi Call your 2nd method in the completion handler of the first. Ensure your first async callback returns successfully before calling the 2nd method. /ravi
更多推荐
如何在Silverlight中等待异步方法
发布评论