private void Log(string message) { if (prog.InvokeRequired) { prog.BeginInvoke((Action)(() => { prog.AppendLogLine(message); })); } else { prog.AppendLogLine(message); } }
private async void Download(BackgroundWorker worker) { tempFolder = Path.GetTempFileName(); File.Delete(tempFolder); Directory.CreateDirectory(tempFolder); using (WebClient client = new WebClient()) { client.DownloadProgressChanged += Client_DownloadProgressChanged; foreach (Package package in packages.CheckedItems) { string file = Path.Combine(tempFolder, package.GetName() + ".zip"); try { await client.DownloadFileTaskAsync(package.GetURI(), file); } catch (WebException ex) { MessageBox.Show("Could not download package " + package.GetName() + ".\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dlDialog.BeginInvoke(new Action(() => dlDialog.Close())); Enabled = true; return; } } } string buildDir = Path.Combine(tempFolder, "build"); worker.DoWork += (obj, e) => { foreach (Package package in packages.CheckedItems) { AddToBuild(Path.Combine(buildDir, package.GetInstallPath()), Path.Combine(tempFolder, package.GetName() + ".zip")); } }; string build = Path.Combine(tempFolder, "build.zip"); worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { ZipFile.CreateFromDirectory(buildDir, build); string emulatorsDir = "emulators"; if (!Directory.Exists(emulatorsDir)) { Directory.CreateDirectory(emulatorsDir); } File.Move(build, Path.Combine(emulatorsDir, config.GetName() + ".zip")); dlDialog.BeginInvoke(new Action(() => dlDialog.Close())); Close(); }; worker.RunWorkerAsync(); }
private async void Download(BackgroundWorker worker) { tempFolder = Path.GetTempFileName(); File.Delete(tempFolder); Directory.CreateDirectory(tempFolder); string buildDir = Path.Combine(tempFolder, "build"); using (WebClient client = new WebClient()) { client.DownloadProgressChanged += Client_DownloadProgressChanged; foreach (Package package in packages.CheckedItems) { try { await package.Download(client, tempFolder); DirectoryInfo dir = await package.Unpack(); AddToBuild(Path.Combine(buildDir, package.GetInstallPath()), dir); } catch (Exception ex) { MessageBox.Show("Could not download package " + package.GetName() + ".\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dlDialog.BeginInvoke(new Action(() => dlDialog.Close())); Enabled = true; return; } } } string build = Path.Combine(tempFolder, "build.zip"); ZipFile.CreateFromDirectory(buildDir, build); string emulatorsDir = "emulators"; if (!Directory.Exists(emulatorsDir)) { Directory.CreateDirectory(emulatorsDir); } File.Move(build, Path.Combine(emulatorsDir, config.GetName() + ".zip")); dlDialog.BeginInvoke(new Action(() => dlDialog.Close())); Close(); }
private void ComicReader_ReportProgress(object sender, ComicReader.ProgressArgs e) { progDialog.SetMaximumValueAsync(e.TotalRecords); progDialog.UpdateProgressAsync(e.TotalProcessed); progDialog.SetDescriptionAsync(e.Description); backgroundProcessDone = e.IsDoneProcessing; if (backgroundProcessDone) { progDialog.BeginInvoke(new Action(() => progDialog.Close())); } }
private void SignalJobIsDone() { // unblock the main thread from ShowDialog() dialog?.BeginInvoke(new Action(() => dialog.Close())); }