How can I run my own asynchronous expected methods?
I see that writing an asynchronous method in some cases is as easy as pie:
private async Task TestGeo() { Geolocator geo = new Geolocator(); Geoposition pos = await geo.GetGeopositionAsync(); double dLat = pos.Coordinate.Latitude; double dLong = pos.Coordinate.Latitude; }
... but, unfortunately, it is also clear that not every method can be made asynchronously by will or not; for wit: this does not work:
private async Task TestAsyncAwait() { int i = await TaSLs_Classes.TASLsUtils.GetZoomSettingForDistance(5); }
... it stops me with a compilation error: "Can't wait for int"; the development time hint also tells me: "The type" int "is not expected"
I also tried this with the same results:
Task<int> i = await TaSLs_Classes.TASLsUtils.GetZoomSettingForDistance(5);
What should I do to make my methods accessible?
UPDATE
As pointed out by Linebacker and S. Cleary (any relation to this cat that used to be on KNBR?), This works:
int i = await Task.Run(() => TaSLs_Classes.TASLsUtils.GetZoomSettingForDistance(5));
... that is, it compiles, but it never "moves."
At runtime, it tells me that I have to βwaitβ CALL for TestAsyncAwait (), but if I do, it will not compile at all ...
c # windows-8 windows-store-apps async-await
B. Clay Shannon Nov 22 '12 at 18:56 2012-11-22 18:56
source share