public Task DownloadAndSaveAsync() { var tcs = new TaskCompletionSource <object>(); _downloadFromInternet.DownloadAsync().ContinueWith(t => { if (t.Exception != null) { tcs.TrySetException(t.Exception.InnerExceptions); return; } _saveToDatabase.SaveAsync(t.Result).ContinueWith(t => { if (t.Exception != null) { tcs.TrySetException(t.Exception.InnerExceptions); } else { tcs.TrySetResult(null); } }); }); return(tcs.Task); }
public async Task DownloadAndSaveAsync() { var task1 = _downloadFromInternet1.DownloadAsync(); var task2 = _downloadFromInternet2.DownloadAsync(); var data = await Task.WhenAll(task1, task2); await _saveToDatabase.SaveAsync(data[0] + data[1]); }
public void DownloadAndSave(Action <Exception> callback) { _downloadFromInternet.DownloadAsync((ex, data) => { if (ex != null) { callback(ex); return; } _saveToDatabase.SaveAsync(data, callback); }); }
public void DownloadAndSaveAsync() { _downloadFromInternet.DownloadCompleted += (_, args) => { if (args.Error != null) { DownloadAndSaveCompleted?.Invoke(this, new AsyncCompletedEventArgs(args.Error, false, null)); return; } var data = args.Data; _saveToDatabase.SaveCompleted += (_, args) => { DownloadAndSaveCompleted?.Invoke(this, new AsyncCompletedEventArgs(args.Error, false, null)); }; _saveToDatabase.SaveAsync(data); }; _downloadFromInternet.DownloadAsync(); }
public Task DownloadAndSaveAsync() { return(_downloadFromInternet.DownloadAsync() .Then(data => _saveToDatabase.SaveAsync(data))); }
private void SaveResults(State state) { _saveToDatabase.SaveAsync(state.Data1 + state.Data2, state.Callback); }
public async Task DownloadAndSaveAsync() { var data = await _downloadFromInternet.DownloadAsync(); await _saveToDatabase.SaveAsync(data); }