Asynchronous Webservice call and abort
-
Hi, i need to make a call to a webservice and in addition abort this call if the response exeeds some specific time. I want to do this because i have to provide a method to the user which returns a value from a webservice through this method not through some callbackevent. This way i decided that it would be a good way to wrap the call to the service in a method, wait for the response (or a specific time, whatever comes first) and return the value to the user. What i have done so far is that i make a call to XXXAsync, hooked up to the return event and set a flag that the webservice responded. In the method called by the user a wait for this flag to be set to true or a specific time, but somehow the webservice return event never fires. If i remove the waiting loop everything works fine. Here is some sample code of the method i want to wrapt the webservice call in:
public float FaceImageQuality(Image faceImage) { this.retrievedFaceQuality = -10; this.faceQualityCheckReturned = false; fvws.FaceQualityAsync(ImageToByteArr(faceImage)); int localCounter = 0; while (localCounter < this.maxWaitTime || this.faceQualityCheckReturned) { localCounter++; Thread.Sleep(100); } if (!this.faceQualityCheckReturned && localCounter >= this.maxWaitTime) throw new Exception(String.Format(this.webServiceDidNotResponded, (this.maxWaitTime * 10), "FaceImageQuality")); return this.retrievedFaceQuality; } private void fvws_FaceQualityCompleted(object sender, FaceValidationClass.FaceValidationWebService.FaceQualityCompletedEventArgs e) { this.retrievedFaceQuality = e.Result; this.faceQualityCheckReturned = true; }
When i remove the Thread.Sleep call and the loop off the code the event fires, but only after the method is left. Does anyone knows a way to solve this? Best regards Jens