public async void StartLoading(IFilePatchAction action) { // Initialize progress-related variables var progressItem = Progress.AddItem(); progressItem.Total = action.PatchSize; // Starts loading an action var task = action.Load(CancellationToken, (done, total) => { // Anonymous function to update progress Debug.Assert(total == progressItem.Total); progressItem.Done = done; ProgressCallback(Progress); }); // Add task to task list; used mostly by 'AwaitAllTasksAndFinish' Tasks.Add(task); // Wait for task to complete await task; // Update progress progressItem.Finish(); ProgressCallback(Progress); }
public async void StartLoading(IFilePatchAction action) { // Initialize progress-related variables var progressItem = _progress.AddItem(); progressItem.Total = action.PatchSize; // Starts loading an action var task = action.Load(_cancellationToken, (done, total, totalThreads) => { // Anonymous function to update progress Debug.Assert(total == progressItem.Total); progressItem.Done = done; _progress.DownloadThreads = totalThreads; _progressCallback(_progress); }); // Add task to task list; used mostly by 'AwaitAllTasksAndFinish' _tasks.Add(task); var guid = Guid.NewGuid(); try { await task; } catch (Exception ex) { // The RenX client seems to crash around here when the cancel button is pressed // while it does crash, it does however achieve our goal of stopping the download // (I'm not saying that it's right, i just dont know how to fix it right now.) Logger.Instance.Write($"{ex.Message}\r\nStack Trace:\r\n{ex.StackTrace}", Logger.ErrorLevel.ErrError); throw; } // Update progress progressItem.Finish(); _progressCallback(_progress); }