示例#1
0
        private void GenerateCars()
        {
            this.DisableSearch();
            var generator = new CarGenerator();

            for (int i = 0; i < this.numberOfCarsToGenerate; i++)
            {
                this.cars.Add(generator.Generate());

                if (i % 10000 == 0)
                {
                    int progress = (int)(((double)i / numberOfCarsToGenerate) * 100);
                    Dispatcher.BeginInvoke(() => this.progressBar.Value = progress);
                }
            }

            this.EnableSearch();
            Dispatcher.BeginInvoke(() => this.progressBar.Visibility = Visibility.Collapsed);
        }
示例#2
0
        private void GenerateCars()
        {
            var generator = new CarGenerator();

            for (int i = 0; i < this.numberOfCarsToGenerate; i++)
            {
                this.cars.Add(generator.Generate());

                if (i % 10000 == 0)
                {
                    int progress = (int)(((double)i / 2000000) * 100);
                    Dispatcher.Invoke(new Action(() => this.progressBar.Value = progress));
                }

                if (i % 200000 == 0)
                {
                    var currentCars = this.cars.ToArray();
                    Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach(this.CarQueries, query =>
                        {
                            query.Run(currentCars, false);
                        });
                    });
                }
            }

            this.EnableSearch();
            Dispatcher.Invoke(new Action(() => this.progressBar.Visibility = Visibility.Collapsed));
        }