I have a ScheduledTaskAgent project the oninvoke() method in ScheduledAgent.cs calls the fetchcurrentdetails() method in a custom defined Class Library project.
In this public string fetchcurrentdetails() method It has the following series of events.
//class variables
string strAddress = string.empty;
public string fetchcurrentdetails()
{
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
if (watcher.Permission == GeoPositionPermission.Granted)
{
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
}
return strAddress ;
}
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
WebClient bWC = new WebClient();
System.Uri buri = new Uri("http://dev.virtual//...");
bWC.DownloadStringAsync(new Uri(buri.ToString()));
bWC.DownloadStringCompleted += new DownloadStringCompletedEventHandler(bHttpsCompleted);
}
private void bHttpsCompleted(object sender, DownloadStringCompletedEventArgs bResponse)
{
//do some data extraction and return the string
strAddress = "This is extracted data";
}
the return statement always returns empty string to calling statement.Any idea how to make sure the execution retains in the class library until the method/event bHttpsCompleted() is completed ? Or what is the way to return the value when the event/method bHttpsCompleted() is fired.
You can modify like this
Call :
await fetchcurrentdetails()