本文整理汇总了C#中System.Windows.Forms.ProgressBar.Report方法的典型用法代码示例。如果您正苦于以下问题:C# ProgressBar.Report方法的具体用法?C# ProgressBar.Report怎么用?C# ProgressBar.Report使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ProgressBar
的用法示例。
在下文中一共展示了ProgressBar.Report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: downloadDriver
/// <summary>
/// Downloads the driver and some other stuff
/// </summary>
private static void downloadDriver()
{
int DateDiff = (DateTime.Now - releaseDate).Days; // how many days between the two dates
string theDate = null;
if (DateDiff == 1) {
theDate = DateDiff + " day ago";
} else if (DateDiff < 1) {
theDate = "today";
} else {
theDate = DateDiff + " days ago";
}
var message = "There is new gpu drivers up for download, do you want to download them now?" + Environment.NewLine + Environment.NewLine;
string key = "Show Driver Description";
string val = null;
// loop
while (val != "true" & val != "false") {
val = SettingManager.readSetting(key); // refresh value each time
if (val == "true") {
message = message + "Description: " + releaseDesc + Environment.NewLine;
} else if (val == "false") {
break;
} else {
// invalid value
SettingManager.setupSetting(key);
}
}
message = message + "Driver version: " + OnlineGPUVersion + " (you're running " + OfflineGPUVersion + ")" + Environment.NewLine +
"Driver released: " + theDate + " (" + releaseDate.ToShortDateString() + ")";
DialogResult dialog = MessageBox.Show(message, "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialog == DialogResult.Yes) {
Console.WriteLine();
// @todo error handling could be better:
// isolate saveFileDialog errors with accually downloading GPU driver
// @todo add status bar for download progress
// @todo do the saveFileDialog in a loop
bool error = false;
try
{
string driverName = downloadURL.Split('/').Last(); // retrives file name from url
DialogResult result;
using (SaveFileDialog saveFileDialog = new SaveFileDialog()) {
saveFileDialog.Filter = "Executable|*.exe";
saveFileDialog.Title = "Choose save file for GPU driver";
saveFileDialog.FileName = driverName;
result = saveFileDialog.ShowDialog(); // show dialog and get status (will wait for input)
switch (result)
{
case DialogResult.OK:
savePath = saveFileDialog.FileName.ToString();
break;
default:
// savePath = Path.GetTempPath() + driverName;
// if something went wrong, fall back to downloads folder
savePath = getDownloadFolderPath() + driverName;
break;
}
}
if (debug == true) {
Console.WriteLine("savePath: " + savePath);
Console.WriteLine("result: " + result);
}
Console.Write("Downloading the driver . . . ");
using (WebClient webClient = new WebClient())
{
var notifier = new AutoResetEvent(false);
var progress = new ProgressBar();
webClient.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
{
progress.Report((double)e.ProgressPercentage / 100);
if (e.BytesReceived >= e.TotalBytesToReceive) notifier.Set();
};
webClient.DownloadFileAsync(new Uri(downloadURL), savePath);
//.........这里部分代码省略.........