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


C# Progress.Increment方法代码示例

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


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

示例1: UpdateWithWorker

        public void UpdateWithWorker(BackgroundWorker worker)
        {
            Progress progress1 = new Progress(0, 3);
            Progress progress2 = new Progress();

            int bytesRead;
            byte[] buffer = new byte[4096];

            worker.ReportProgress(DisplayProgress1, progress1);

            // Download File List
            using (WebClient client = new WebClient())
            {
                worker.ReportProgress(DisplayProgressText1, "Downloading File List ...");
                worker.ReportProgress(DisplayProgressText2, String.Empty);
                string files;
                try
                {
                    files = client.DownloadString(FileListUrl);
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Could not download file-list.\nDetails: " + e.Message, e);
                }
                progress1.Increment();
                worker.ReportProgress(DisplayProgress1, progress1);

                worker.ReportProgress(DisplayProgressText1, "Validating File List ...");
                worker.ReportProgress(DisplayProgressText2, String.Empty);
                Items.Clear();
                StringReader reader = new StringReader(files);
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] fragments = line.Split('\t');
                    UpdateItem item = new UpdateItem(m_RootPath);
                    if (fragments.Length >= 1)
                    {
                        item.FileName = fragments[0];
                        if (String.Equals(Path.GetFullPath(item.FileName), Path.GetFullPath(Application.ExecutablePath), StringComparison.InvariantCultureIgnoreCase))
                        {
                            item.TargetFileName = item.FileName + ".tmp";
                            SelfUpdateDetected = true;
                            SelfUpdateItem = item;
                        }
                        if (String.IsNullOrEmpty(item.FileName)) continue;
                        m_Items.Add(item);
                    }
                    if (fragments.Length >= 2)
                    {
                        item.Hash = fragments[1];
                    }
                    line = reader.ReadLine();
                }
                progress1.Increment();
                worker.ReportProgress(DisplayProgress1, progress1);

                if (worker.CancellationPending) return;

                progress2.Reset(0, Items.Count);
                worker.ReportProgress(DisplayProgress2, progress2);
                worker.ReportProgress(DisplayProgressText1, "Validating Files ...");
                Crc32Processor processor = new Crc32Processor();
                foreach (UpdateItem item in Items)
                {
                    if (worker.CancellationPending) return;
                    worker.ReportProgress(DisplayProgressText2, item.FullName);

                    if (File.Exists(item.FullName) == false)
                    {
                        item.CheckStatus = UpdateCheckStatus.NotExisiting;
                        item.IsUpdateRequired = true;
                    }
                    else
                    {
                        using (FileStream fs = File.OpenRead(item.FullName))
                        {
                            while (true)
                            {
                                bytesRead = fs.Read(buffer, 0, buffer.Length);
                                processor.Process(buffer, 0, bytesRead);
                                if (bytesRead != buffer.Length) break;
                            }
                        }
                        if (item.Hash != processor.Current.ToString("X8"))
                        {
                            item.CheckStatus = UpdateCheckStatus.HashMismatch;
                            item.IsUpdateRequired = true;
                        }
                        else
                        {
                            item.CheckStatus = UpdateCheckStatus.Ok;
                        }
                        processor.Reset();
                    }

                    progress2.Increment();
                    worker.ReportProgress(DisplayProgress2, progress2);
                }
                progress1.Increment();
//.........这里部分代码省略.........
开发者ID:RavenB,项目名称:Earth-and-Beyond-server,代码行数:101,代码来源:Updater.cs


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