private async Task RecoverDownloads() { var downloads = await BackgroundDownloader.GetCurrentDownloadsAsync(); foreach (DownloadOperation download in downloads) { try { SignalAttachment attachment = SignalDBContext.GetAttachmentByGuidNameLocked(download.Guid.ToString()); if (attachment != null) { if (!Downloads.ContainsKey(attachment.Id)) { Logger.LogInformation("Creating attach task for attachment {0} ({1})", attachment.Id, download.Guid); Downloads.Add(attachment.Id, download); var t = Task.Run(async() => { await download.AttachAsync(); await HandleSuccessfullDownload(attachment, download.ResultFile, download); }); } else { Logger.LogInformation("Attachment {0} ({1}) already has a running task", attachment.Id, download.Guid); } } else { Logger.LogInformation("Aborting unrecognized download {0}", download.Guid); download.AttachAsync().Cancel(); } } catch (Exception e) { Logger.LogError("TriageDownloads encountered an error: {0}\n{1}", e.Message, e.StackTrace); } } }