c# - Threading - make sure the thread finishes -
solved: http://msdn.microsoft.com/en-us/library/ff431782(v=vs.92).aspx
i have following class give me current location in wp7:
public class position { private geocoordinatewatcher watcher = null; public geocoordinate currentlocation { get; set; } public position() { obtaincurrentlocation(); } private void obtaincurrentlocation() { watcher = new geocoordinatewatcher(geopositionaccuracy.default); watcher.positionchanged += new eventhandler<geopositionchangedeventargs<geocoordinate>>(watcher_positionchanged); watcher.start(); } void watcher_positionchanged(object sender, geopositionchangedeventargs<geocoordinate> e) { //stop & clean up, don't need anymore watcher.stop(); watcher.dispose(); watcher = null; currentlocation = e.position.location; } }
i want use location. instantiate it. how can make sure that, when call currentlocation property, location whould have been acquired?
you can make position class implement inotifypropertychanged , raise propertychanged when value of currentlocation property has changed.
code depends on currentlocation listen position.propertychanged , act appropriately when event raised.
Comments
Post a Comment