Exemple #1
0
        private void DoWork(IWork work)
        {
            try
            {
                this.NotifyObservers(work, work.GetResult());
            }
            catch (Exception exception)
            {
                Exception e = exception;
                switch (this.ExceptionHandling)
                {
                case ExceptionHandlingAction.DefaultBehaviour:
                {
                    throw;
                }

                case ExceptionHandlingAction.CallEventHandler:
                {
                    this.OnException(e);
                    break;
                }

                case ExceptionHandlingAction.CallEventHandlerAndLeakException:
                {
                    this.OnException(e);
                    throw;
                }
                }
            }
        }
Exemple #2
0
        public void BanchMark_TimeAlgoritm()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            _specificationWork = new SpecificationXmlWork(model: _specification);
            _specificationWork.GetResult();
            stopwatch.Stop();
            Console.WriteLine
                (value: $"Время обработки маленького файла в одном потоке: {stopwatch.Elapsed}");
            stopwatch.Reset();

            _specification = new Specification();
            _loaderXml     = new LoaderXml(pathXml: "specification.xml", model: _specification);
            _loaderXml.LoadData();
            _specification = ((LoaderXml)_loaderXml).Model;
            stopwatch.Start();
            _specificationWork = new SpecificationXmlWork(model: _specification);
            _specificationWork.GetResultAsync();
            stopwatch.Stop();
            Console.WriteLine
            (
                value:
                $"Время обработки в многопоточном режиме маленького файла: {stopwatch.Elapsed}"
            );

            _specification = new Specification();
            _loaderXml     = new LoaderXml(pathXml: "big_specification.xml", model: _specification);
            _loaderXml.LoadData();
            _specification = ((LoaderXml)_loaderXml).Model;
            stopwatch.Start();
            _specificationWork = new SpecificationXmlWork(model: _specification);
            _specificationWork.GetResult();
            stopwatch.Stop();
            Console.WriteLine
                (value: $"Время обработки в одном потоке большого файла: {stopwatch.Elapsed}");
            stopwatch.Reset();

            _specification = new Specification();
            _loaderXml     = new LoaderXml(pathXml: "big_specification.xml", model: _specification);
            _loaderXml.LoadData();
            _specification = ((LoaderXml)_loaderXml).Model;
            stopwatch.Start();
            _specificationWork = new SpecificationXmlWork(model: _specification);
            _specificationWork.GetResultAsync();
            stopwatch.Stop();
            Console.WriteLine
            (
                value: $"Время обработки в многопоточном режиме большого файла: {stopwatch.Elapsed}"
            );
        }