当前位置: 首页>>代码示例>>C#>>正文


C# ProgressBar.Dispose方法代码示例

本文整理汇总了C#中System.Windows.Forms.ProgressBar.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ProgressBar.Dispose方法的具体用法?C# ProgressBar.Dispose怎么用?C# ProgressBar.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ProgressBar的用法示例。


在下文中一共展示了ProgressBar.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

        private void cancelbutton_click
            (object sender, EventArgs e, WebClient client,PictureBox cancelbutton,
            ProgressBar progressbar,string filename,TextBox episode = null)
        {
            const string message = "确定取消下载么?";
            const string caption = "取消下载";
            if (cancelbutton.Name.StartsWith("batch"))
            {
                client.CancelAsync();
                client.Dispose(); //without it, deleting file would fail.
                batchpanel.Controls.Remove(episode);
                batchpanel.Controls.Remove(cancelbutton);
                batchpanel.Controls.Remove(progressbar);
                cancelbutton.Dispose();
                progressbar.Dispose();
                episode.Dispose();
                File.Delete(filename);
            }
            else 
            {
                var result = System.Windows.Forms.MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    client.CancelAsync();
                    client.Dispose();
                    infopanel.Controls.Remove(cancelbutton);
                    infopanel.Controls.Remove(progressbar);
                    cancelbutton.Dispose();
                    progressbar.Dispose();
                    File.Delete(filename);
                }
            }

        }
开发者ID:polyval,项目名称:ESLPodcast,代码行数:34,代码来源:MainForm.cs

示例2: downloadDriver


//.........这里部分代码省略.........
                // 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);

                        notifier.WaitOne(); // sync with the above
                        progress.Dispose(); // get rid of the progress bar
                    }

                }
                catch (Exception ex)
                {
                    error = true;
                    Console.Write("ERROR!");
                    LogManager.log(ex.Message, LogManager.Level.ERROR);
                    Console.WriteLine();
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine();
                }

                if (error == false)
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                Console.WriteLine();
                Console.WriteLine("The downloaded file has been saved at: " + savePath);

                dialog = MessageBox.Show("Do you want view the release PDF?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes) {
                    try {
                        Process.Start(pdfURL);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                dialog = MessageBox.Show("Do you wish to run the driver installer?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes) {
                    try {
                        Process.Start(savePath);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }

                }
            }
        }
开发者ID:ElPumpo,项目名称:TinyNvidiaUpdateChecker,代码行数:101,代码来源:MainConsole.cs


注:本文中的System.Windows.Forms.ProgressBar.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。