public Task GetOrDownloadAsync(string url) { //simulate image download IPendingOperation pendingOperation = null; Console.WriteLine($"Downloading {url}"); Task.Delay(2000).ContinueWith(_ => { Console.WriteLine($"Downloaded {url}"); pendingOperation.Complete(); }); pendingOperation = ServiceRef.RegisterPendingOperation(this, actionOnCompletion: (res) => { //Accessing _images here would be risky, just wrap the call... ServiceRef.Call(this, () => { Console.WriteLine($"Adding to images {url}"); _images.Add(new ImageStuff() { Url = url, Data = new byte[] { 0x01 } }); Console.WriteLine($"Added to images {url}"); }); }); return(Task.CompletedTask); }
public void CompleteOperation() { OperationCompleted = true; _pendingOperation.Complete(); }
public Task CompleteOperationAsync() { OperationCompleted = true; _pendingOperation.Complete(); return(Task.CompletedTask); }