BuildTools.BuildTools.Progress C# (CSharp) Method

Progress() public method

Set the progress bar to the specified place.
public Progress ( int place, int total ) : void
place int Current progress to this point
total int Total progress to completion
return void
        public void Progress(int place, int total)
        {
            if (InvokeRequired) {
                Invoke(_progressPercentDelegate, place, total);
            } else {
                progress.Style = ProgressBarStyle.Continuous;
                progress.Minimum = 0;
                progress.Maximum = total;
                progress.Value = place;
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Given a URL, download the file from that URL to a destination file. Returns whether the download
        /// was successful. This automatically adds the download to the list of disposables, and removes it
        /// when the download is completed.
        /// </summary>
        /// <param name="url">The URL to download the file from</param>
        /// <param name="dest">The relative or absolute path to the destination file to be saved</param>
        /// <returns>True if the download is successful</returns>
        private bool DownloadFile(string url, string dest)
        {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //TLS 1.2

            using (WebClient client = new WebClient()) {
                _disposables.Add(client);
                try {
                    client.DownloadProgressChanged += (sender, e) => {
                        double bytesIn    = e.BytesReceived;
                        double totalBytes = e.TotalBytesToReceive;
                        if (totalBytes < 0)
                        {
                            _form.ProgressIndeterminate();
                        }
                        else
                        {
                            _form.Progress((int)bytesIn, (int)totalBytes);
                        }
                    };

                    client.DownloadFileAsync(new Uri(url), dest);
                    // Make this thread wait for the download to finish
                    while (client.IsBusy)
                    {
                        Thread.Sleep(50);
                    }
                } catch (Exception) {
                    return(false);
                } finally {
                    _disposables.Remove(client);
                }
            }
            return(true);
        }
All Usage Examples Of BuildTools.BuildTools::Progress