FeatureLayer extension method using the async\await  pattern

2465
1
02-23-2014 11:36 AM
by Anonymous User
Not applicable
Original User: effortlesswebsllc

I would like to create an extension method on the FeatureLayer class called, UpdateAsync.  I have the extension method working, however I would like to know if I coded it correctly.

        public static async Task<FeatureLayer> UpdateAsync(this FeatureLayer fl   )
        {
            TaskCompletionSource<FeatureLayer> tcs = new TaskCompletionSource<FeatureLayer>();

            fl.UpdateCompleted += (o, e) =>
                {
                    tcs.TrySetResult((FeatureLayer)o);
                };

            fl.UpdateFailed += (o, e) =>
                {
                    tcs.SetException(e.Error);
                };

            fl.Update();

            return await tcs.Task;
0 Kudos
1 Reply
AnttiKajanus1
Regular Contributor II
Hey,

Check this short video about using TaskCompletitionSource. It gives good description.

Remember to unhook events.
0 Kudos