public void Download() { progressBar.BeginInvoke(new SetProgressBarValueDelegate(SetProgressBarValue), progressBar, 0); lblFilename.BeginInvoke(new SetLabelTextDelegate(SetLabelText), lblFilename, downloader.Filename); lblProxy.BeginInvoke(new SetLabelTextDelegate(SetLabelText), lblProxy, "P: " + downloader.GetProxyAddress()); lblDownload.BeginInvoke(new SetLabelTextDelegate(SetLabelText), lblDownload, string.Format("D: {0:n}/{1:n} MB", 0, 0)); lblSpeed.BeginInvoke(new SetLabelTextDelegate(SetLabelText), lblSpeed, string.Format("S: {0:n4} MB/s", 0)); lblTimeLeft.BeginInvoke(new SetLabelTextDelegate(SetLabelText), lblTimeLeft, "L: 00:00:00.0000"); Application.DoEvents(); string downloadLink = Downloader.DownloadLink; string saveFolder = Downloader.SaveDirectory; int result = Downloader.Start(); lock (Utils.Proxies) { while ((result == 403 || result == -1) && (Utils.Proxies.Count() > 0)) { string proxy = Utils.Proxies[0]; if (!String.IsNullOrEmpty(proxy)) { Downloader = new Downloader(downloadLink, saveFolder, new WebProxy(proxy)); result = Downloader.Start(); } Utils.Proxies.RemoveAt(0); } } }
void startThread() { string pa = pathFinder; GetAll(pa, files); try { w.BeginInvoke(new setProgressBar(b => { w.Minimum = 0; w.Maximum = b; }), new object[] { files.Count }); } catch { return; } int i = 0; foreach (var file in files) { if (NameOfHash == "MD5") { file.Hash = file.GetHashMD5(); } else { file.Hash = file.GetHash32(); } i++; w.BeginInvoke(new setProgressBar(b => { w.Value = b; l2.Text = b.ToString(); if (b == w.Maximum) { dataGridView1.DataSource = files; } }), new object[] { i }); } }
private void fillProgressBar(ProgressBar pb, Label l) { Thread backgroundThread = new Thread( new ThreadStart(() => { for (int n = 0; n < 100; n++) { Thread.Sleep(50); pb.BeginInvoke( new Action(() => { pb.Value = n; } )); } MessageBox.Show("Thread completed!"); l.Text = " "; pb.BeginInvoke( new Action(() => { pb.Value = 0; } )); } )); backgroundThread.Start(); }
/// <summary> /// Advances progress-bar if possible. /// </summary> /// <param name="Event">Event from which sender model's simulation time is read.</param> /// <remarks> /// If <c>Event</c> is /// <see cref="CompositionManager.SimulationFinishedEvent">CompositionManager.SimulationFinishedEvent</see> /// or <see cref="CompositionManager.SimulationFailedEvent">CompositionManager.SimulationFailedEvent</see>, /// the progress bar value is set to maximum and progress bar is disabled. This way the window /// hosting progress bar determines that simulation finished. /// See <see cref="IListener.OnEvent">IListener.OnEvent</see> /// for more detail.</remarks> public void OnEvent(IEvent Event) { if (Event == CompositionManager.SimulationFinishedEvent || Event == CompositionManager.SimulationFailedEvent) { // Simulation has finished, so disable progress bar, // RunBox form catches this event so it knows, when simulation finished if (_progressBar.InvokeRequired) { _progressBar.BeginInvoke(new UpdateProgressBarDelegate2(UpdateProgressBar2), new object[] { ProgressBarMaximum, false }); } else { _progressBar.Maximum = ProgressBarMaximum; _progressBar.Enabled = false; } } else { if (Event.SimulationTime != null) { if (Event.SimulationTime.ModifiedJulianDay > _maximumTime) { _maximumTime = Event.SimulationTime.ModifiedJulianDay; int progressBarValue = (int)(ProgressBarMaximum * (_maximumTime - _simulationTimeHorizon.Start.ModifiedJulianDay) / (_simulationTimeHorizon.End.ModifiedJulianDay - _simulationTimeHorizon.Start.ModifiedJulianDay)); // Use BeginInvoke for case this method is called from different thread than // the _progressBar's owner (otherwise application would hang here). // Asynchronous version is used for case that thread is blocked. _progressBar.BeginInvoke(new UpdateProgressBarDelegate(UpdateProgressBar), new object[] { progressBarValue }); } } } }
public static void UpdateProgress() { _loadingProgressBar.Maximum = 211; if (_loadingProgressBar.InvokeRequired) { _loadingProgressBar.BeginInvoke((MethodInvoker) delegate { _loadingProgressBar.Value = _loadingProgressBar.Value + 1; }); } else { _loadingProgressBar.Value = _loadingProgressBar.Value + 1; } _loadingProgressBar.Refresh(); _loadingProgressBar.Update(); }
public static void ProgressBar(ProgressBar progressBar, int percent) { progressBar.BeginInvoke((MethodInvoker) delegate { progressBar.Value = percent > 100 ? 100 : percent; }); }
public void UpdateProgress(string entryName) { try { if (entryName == null || Label == null || ProgressBar == null) { return; } Label.BeginInvoke((MethodInvoker) delegate { string fullName = entryName; int fullNameLength = fullName.Length; if (fullNameLength > MaxLableLength) { fullName = String.Format("...{0}", fullName.Substring(fullName.Length - MaxLableLength)); } Label.Text = fullName; }); ProgressBar.BeginInvoke((MethodInvoker) delegate { ProgressBar.PerformStep(); }); } catch (Exception ex) { Helpers.WriteToLog(Resources.Error_message, ex.Message); } }
private void showProgress(ProgressBar progressbar, int prg) { if (this.WindowState == FormWindowState.Minimized) { return; } if (progressbar.InvokeRequired) { progressbar.BeginInvoke(new ShowProgress(showProgress), new object[] { progressbar, prg }); } else { if (prg < progressbar.Maximum) { progressbar.Value = prg; } else { progressbar.Value = progressbar.Maximum; } } }
public override int Read(byte[] buffer, int offset, int count) { lock (this) { if (abort) { throw new IOException("aborted"); } int len = fs.Read(buffer, offset, count); readcount += len; if (readcount > readnotifycount) { readcount = 0; // readcount-=readnotifycount; // if (ProgressUpdate!=null) // ProgressUpdate(this.Position, this.Length); if (progressBar != null) { progressBar.BeginInvoke(new ProgressUpdateEvent(ProgressBarUpdateProc), new object[] { 0, 0 }); } } return(len); } }
private void UpdateProgressBar() { //Debug.WriteLine("------------- " + progressBar.Value); progressBar.BeginInvoke(new InvokeDelegate(InvokeMethod)); //progressBar.PerformStep(); }
// Reader Caller Section Start Here public int ReadDataSaleRegister(string fname, int start, int end, ProgressBar pBar, string tablename) { //GST Features Added DataTable dt = new DataTable(tablename); int Row = 0; int r = 0, c = 0; SaleRegister sr; Logs.LogMe("Started reading"); foreach (var worksheet in Workbook.Worksheets(fname)) { Logs.LogMe(worksheet.ToString()); foreach (var row in worksheet.Rows) { //Logs.LogMe ("Row=" + row.ToString () + "RowNo=" + Row); if (Row <= end) { if (Row >= start) { Logs.LogMe("iRow=" + r); sr = new SaleRegister(); c = 0; foreach (var cell in row.Cells) { if (cell != null) { c = AddCol(cell, ref sr, c); } else { Logs.LogMe("C=" + c + "Null"); } c++; } if (Db.SaveRowData(sr) > 0) { r++; pBar.BeginInvoke(new Action(() => { pBar.PerformStep(); })); Logs.LogMe("Row=" + r + " got saved"); } } Row++; // Logs.LogMe ("Row will be" + Row + "\tr=" + r); } else { Logs.LogMe("End Target Matched , Breaking out now"); break; } } } Logs.LogMe("end , record=" + r); return(r); }
private void DownByStream() { stopDown = false; Stream fs = null; try { //获取下载文件长度 fileLength = getDownLength(url); downLength = 0; if (fileLength > 0) { //判断并建立文件 if (createFile(fileName)) { WebClient DownFile = new WebClient(); using (Stream str = DownFile.OpenRead(url)) { byte[] mbyte = new byte[1024]; int readL = str.Read(mbyte, 0, 1024); fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write); //读取流 while (readL != 0) { if (stopDown) { break; } downLength += readL; //已经下载大小 fs.Write(mbyte, 0, readL); //写文件 readL = str.Read(mbyte, 0, 1024); //读流 if (progressBar != null) { progressBar.BeginInvoke(new ActionWithTwoLongParameters(UpdateProgress), downLength, fileLength); } } } } } } catch (Exception e) { //if (e.Message.Contains("超时") || e.Message.ToLower().Contains("timeout")) // return; //else { ErrorMsg = e.Message; } } finally { if (fs != null) { fs.Close(); fs = null; } } }
public void UpdateProgress(int progress) { ProgressBar.BeginInvoke( new Action(() => { ProgressBar.Value = progress; } )); }
public void UpdateBar(int percent) { ProgressBar.BeginInvoke( new Action(() => { ProgressBar.Value = percent; } )); }
private void UpdateProgressBar(int percentage) { if (progressBar == null) { return; } progressBar.BeginInvoke((MethodInvoker) delegate { progressBar.Value = percentage; }); }
internal void Message(string data) { if (data == null) { return; } var compileMatch = Regex.Match(data, @"===info \|\|\| Progress \{0\} \|\|\| \[(\d+).*\]"); if (compileMatch.Success) { var value = int.Parse(compileMatch.Groups[1].Value); if (value == 100) { progressBar_compileUpload.BeginInvoke(new MethodInvoker(() => progressBar_compileUpload.Value = 0)); return; } progressBar_compileUpload.BeginInvoke(new MethodInvoker(() => progressBar_compileUpload.Value = value)); return; } var uploadMatch = Regex.Match(data, @"(Reading|Writing) \| #+ \| (\d+)%"); if (uploadMatch.Success) { progressBar_compileUpload.BeginInvoke(new MethodInvoker(() => progressBar_compileUpload.Value += 33)); return; } var uploadErrorMatch = Regex.Match(data, @"can't open device"); if (uploadErrorMatch.Success) { throw new Exception("Com port cannot be opened! Make sure device is connected."); } var compileErrorMatch = Regex.Match(data, @"(?<=\w+Ex )(.+)"); if (compileErrorMatch.Success) { throw new Exception("Error Compiling: " + compileErrorMatch.Groups[0]); } Console.WriteLine(data); }
public static void SetMaximumInvoke(this ProgressBar p, int Maximum) { if (p.InvokeRequired) { p.BeginInvoke((MethodInvoker) delegate { p.SetMaximumInvoke(Maximum); }); } else { p.Maximum = Maximum; } }
private void InitalState(ProgressBar pgb, bool b = false) { Action act = () => { pgb.Maximum = 0; pgb.Value = 0; //ktuple int seqNum = 0; foreach (TreeNode node in ListNode) { seqNum += node.Nodes.Count; } if (b) { seqNum += ListNode.Count; } pgb.Maximum += seqNum * ListK.Count; int tmpK = 0; foreach (var item in ListK) { if (item > 2) { tmpK++; } } bool bMarkov = false; foreach (var item in listFun) { if (item == "Eu" || item == "Ma" || item == "Ch" || item == "D2") { pgb.Maximum += ListK.Count * ListNode.Count; } else if (item == "D2S" || item == "D2Star") { pgb.Maximum += tmpK * listM.Count * ListNode.Count; if (!bMarkov) { pgb.Maximum += tmpK * seqNum * listM.Count; bMarkov = true; } } else if (item == "Hao") { pgb.Maximum += tmpK * ListNode.Count; pgb.Maximum += tmpK * seqNum; } } }; pgb.BeginInvoke(act); }
public static void SetValueNoAnimationInvoke(this ProgressBar p, int value) { if (p.InvokeRequired) { p.BeginInvoke((MethodInvoker) delegate { p.SetValueNoAnimation(value); }); } else { p.SetValueNoAnimation(value); } }
public static void SetValueInvoke(this ProgressBar p, int Value) { if (p.InvokeRequired) { p.BeginInvoke((MethodInvoker) delegate { p.SetValueInvoke(Value); }); } else if (Value <= p.Maximum) { p.Value = Value; } }
private void UpdateProgressBar(ProgressBar bar, int maxValue, int current) { if (bar.InvokeRequired) { bar.BeginInvoke(new Action <ProgressBar, int, int>(UpdateProgressBar), bar, maxValue, current); } else { bar.Maximum = maxValue; bar.Value = current; bar.Update(); bar.Parent.Update(); } }
// Expand a Gateway RAM Dump File to a RAW (absolute) RAM Dump File public bool dumpGWRAM(GWFileHeader activeDump, ProgressBar progress) { var zeropad = new byte[1024]; var readbuffer = new byte[1024]; int bytesread = 0; string outpath = System.IO.Path.GetDirectoryName(activeDump.filePath); outpath += "\\" + System.IO.Path.GetFileNameWithoutExtension(activeDump.filePath); outpath += "-raw" + System.IO.Path.GetExtension(activeDump.filePath); // Read/Write using (FileStream filer = File.OpenRead(activeDump.filePath)) { using (FileStream filew = File.Create(outpath)) { filer.Seek(activeDump.headerSize, 0); for (int currentRegion = 0; currentRegion < activeDump.memRegionCount; currentRegion++) { while (filew.Position < activeDump.memRegions[currentRegion][0]) { int thischunk = (int)(activeDump.memRegions[currentRegion][0] - filew.Position); if (thischunk > zeropad.Length) { thischunk = zeropad.Length; } filew.Write(zeropad, 0, thischunk); } filew.Flush(); while (filew.Position < activeDump.memRegions[currentRegion][1]) { int thisblock = (int)(activeDump.memRegions[currentRegion][1] - filew.Position); if (thisblock > readbuffer.Length) { thisblock = readbuffer.Length; } bytesread = filer.Read(readbuffer, 0, thisblock); filew.Write(readbuffer, 0, bytesread); } filew.Flush(); progress.BeginInvoke( new Action(() => { progress.Value++; } )); } } // Using File.OpenWrite } // Using File.OpenRead return(true); }
private void OkButtonClick(object sender, EventArgs e) { if (!(Subsongs.SelectedItem is MultiDumperWrapper.Song song)) { return; } if (song.GetLength() <= TimeSpan.Zero) { // Try to parse the text box if (!TimeSpan.TryParseExact(lengthBox.Text, "m\\:ss", null, out var length)) { return; } song.ForceLength = length; } OKButton.Enabled = false; // We start a task to wrap the load task Task.Factory.StartNew(() => { try { Filenames = _wrapper.Dump(song, progress => { ProgressBar.BeginInvoke( new Action(() => ProgressBar.Value = (int)(progress * 100))); }).ToList(); BeginInvoke(new Action(() => { DialogResult = DialogResult.OK; Close(); })); } catch (Exception) { BeginInvoke(new Action(() => { DialogResult = DialogResult.Cancel; Filenames = null; Close(); })); } }); }
public static void AddProgressValue(ProgressBar ctrl, int value) { if (ctrl.InvokeRequired) { ctrl.BeginInvoke(new AddProgressValueHandler(AddProgressValue), ctrl, value); return; } try { ctrl.Value = value; } catch (Exception) { } }
private void Update_ProgressBar(ProgressBar progressBar, int finishedFrameCount, int totalFrameCount) { try { progressBar.BeginInvoke((MethodInvoker) delegate() { int i = finishedFrameCount * progressBar.Maximum / totalFrameCount; progressBar.Value = Math.Min(progressBar.Maximum, i); }); } catch (System.InvalidOperationException e) { Debug.Write(e.ToString()); } }
private void SetProgressBarValue(ProgressBar pb, int value) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (pb.InvokeRequired) { SetProgressBarValueCallback d = new SetProgressBarValueCallback(SetProgressBarValue); pb.BeginInvoke(d, new object[] { pb, value }); } else { pb.Value = value; } }
public static void SetValue(this ProgressBar pb, int nv) { if (pb.InvokeRequired) { pb.BeginInvoke(new MethodInvoker( delegate() { SetValue(pb, nv); } )); } else { pb.Value = nv; } }
private void setProgressValue(ProgressBar progressBar) { ChangeProgressValueDelegate p = new ChangeProgressValueDelegate(() => { for (int i = 0; i <= 100; i++) { progressBar.Value = i; Thread.Sleep(50); } }); if (progressBar.InvokeRequired) { progressBar.BeginInvoke(p); } Console.WriteLine($"当前线程ID:{Thread.CurrentThread.ManagedThreadId}"); }
private void SetProgressBarParams(ProgressBar pb, int minimum, int maximum, int step) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (pb.InvokeRequired) { SetProgressBarParamsCallback d = new SetProgressBarParamsCallback(SetProgressBarParams); pb.BeginInvoke(d, new object[] { pb, minimum, maximum, step }); } else { pb.Minimum = minimum; pb.Maximum = maximum; pb.Step = step; } }
public static void SetValue(this ProgressBar pBar, long value) { if (pBar.IsHandleCreated) { if (pBar.InvokeRequired) { pBar.BeginInvoke((MethodInvoker) delegate() { SendMessage(pBar.Handle, 1026, (IntPtr)value, IntPtr.Zero); }); } else { SendMessage(pBar.Handle, 1026, (IntPtr)value, IntPtr.Zero); } } }
public void setProgressBarMax(ProgressBar bar, int new_max) { if(bar.InvokeRequired) { bar.BeginInvoke(new setProgressBarMaxDelegate(setProgressBarMax),new Object[] {bar,new_max}); } else { lock(bar) { bar.Maximum = new_max; bar.Update(); } } }
public void setProgressBarMin(ProgressBar bar, int new_min) { if(bar.InvokeRequired) { bar.BeginInvoke(new setProgressBarMinDelegate(setProgressBarMin),new Object[] {bar,new_min}); } else { lock(bar) { bar.Minimum = new_min; bar.Update(); } } }
public void setProgressBarValue(ProgressBar bar, int new_value) { if(bar.InvokeRequired) { bar.BeginInvoke(new setProgressBarValueDelegate(setProgressBarValue),new Object[] {bar,new_value}); } else { lock(bar) { if(new_value>bar.Maximum) bar.Value = bar.Maximum; else if(new_value<bar.Minimum) bar.Value = bar.Minimum; else bar.Value = new_value; bar.Update(); } } }
public void performStep(ProgressBar bar) { if(bar.InvokeRequired) { bar.BeginInvoke(new performStepDelegate(performStep), new Object[] { bar }); } else { lock(bar) { bar.Increment(1); bar.Update(); } } }