CSPspEmu.Gui.Winforms.ProgressForm.SetProgress C# (CSharp) Method

SetProgress() public method

public SetProgress ( string Title, int Current, int Total ) : void
Title string
Current int
Total int
return void
        public void SetProgress(string Title, int Current, int Total)
        {
            try
            {
                this.Invoke(new Action(() =>
                {
                    label1.Text = Title;
                    try
                    {
                        Current = Math.Min(Math.Max(0, Current), Total);
                        progressBar1.Minimum = 0;
                        progressBar1.Maximum = Total;
                        progressBar1.Value = Current;
                    }
                    catch
                    {
                    }
                }));
            }
            catch
            {
            }
        }

Usage Example

Example #1
0
        public void Init(string IsosPath, string CachePath)
        {
            if (IsosPath == null)
            {
                return;
            }
            var ProgressForm = new ProgressForm();
            try
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    var GameList = new GameList();
                    Console.WriteLine("Reading ISOs...");
                    GameList.Progress += (Title, Current, Total) =>
                    {
                        //Console.WriteLine("Progress: {0}, {1}/{2}", Title, Current, Total);
                        ProgressForm.SetProgress(Title, Current, Total);
                    };

                    var List = new List<GameList.GameEntry>();

                    GameList.EntryAdded += (Entry, Cached) =>
                    {
                        //Console.WriteLine("aaaaaaaa");
                        List.Add(Entry);
                        if (!Cached)
                        {
                            objectListView1.AddObject(Entry);
                        }
                    };

                    GameList.ScanPath(IsosPath, CachePath);

                    this.Invoke(new Action(() =>
                    {
                        objectListView1.SetObjects(List);
                        objectListView1.Sort(TitleColumn, SortOrder.Ascending);
                    }));

                    Console.WriteLine("Done");
                    /*
                    foreach (var Entry in GameList.Entries)
                    {
                        Console.WriteLine(Entry.TITLE);
                    }
                    */

                    ProgressForm.End();
                }, null);

                this.Invoke(new Action(() =>
                {
                    ProgressForm.ShowDialog();
                }));
            }
            finally
            {
                ProgressForm.End();
            }
        }