private void WorkerOnStatusChanged(INotifyThreadStatus sender, StatusChangedEventArgs args) { if (args.AttachedData?.guid != Guid ?? false) { return; } _worker.StatusChanged -= WorkerOnStatusChanged; _database.SetZipFileLocation(Guid, args.AttachedData.destinationPath); WebFileLocation = args.AttachedData.destinationPath; string userstory = null, exception; using (ZipArchive archive = new ZipArchive(File.OpenRead(args.AttachedData.destinationPath), ZipArchiveMode.Read, false)) { ZipArchiveEntry userstoryEntry = archive.GetEntry("userstory.txt"); if (userstoryEntry != null) { using (Stream s = userstoryEntry.Open()) { byte[] buffer = new byte[userstoryEntry.Length]; s.Read(buffer, 0, buffer.Length); userstory = Encoding.UTF8.GetString(buffer); } } ZipArchiveEntry exceptionEntry = archive.GetEntry("exception.txt"); using (Stream s = exceptionEntry.Open()) { byte[] buffer = new byte[exceptionEntry.Length]; s.Read(buffer, 0, buffer.Length); exception = Encoding.UTF8.GetString(buffer); } } Userstory = userstory; StackTrace = exception; _database.SetStackTrace(Guid, exception); if (userstory != null) { _database.SetUserStory(Guid, userstory); } Progress = CrashReportProcessingProgress.Downloaded; }
//This is used to subscribe to an action happening on another thread. Least ugly way i know to re-route it to ui thread private void OtherThreadNotificationHandler(INotifyThreadStatus sender, StatusChangedEventArgs args) { try { if (Disposing || IsDisposed) { return; } Invoke(_mainThreadDelegate, sender, args); } catch { // ignored } }
private void MainThreadAction(INotifyThreadStatus sender, StatusChangedEventArgs args) { if (_statusLabels.TryGetValue(sender, out ToolStripItem item)) { item.Text = $"{sender.Name}: {args.Status}"; } else { item = tsBackground.Items.Add($"{sender.Name}: {args.Status}"); _statusLabels.Add(sender, item); } if (_specificHandlers.TryGetValue(sender.Name, out Action <StatusChangedEventArgs> action)) { action(args); } }