示例#1
0
        public static void Work()
        {
            while (true)
            {
                KeyValuePair <MainLogic, Config> item;
                lock (_workQueue)
                {
                    if (!_workQueue.Any())
                    {
                        return;
                    }
                    item = _workQueue.Dequeue();
                }

                MainLogic logic            = item.Key;
                Config    config           = item.Value;
                var       LogUpdate        = logic.LogUpdate;
                var       StatusUpdate     = logic.StatusUpdate;
                var       PercentageUpdate = logic.PercentageUpdate;
                var       _info            = logic._info;

                try
                {
                    var result = logic.Go(config) == 0 ? 100 : -99;

                    if (result == 100)
                    {
                        if (LogUpdate != null)
                        {
                            LogUpdate("Finished.", _info);
                        }
                        if (StatusUpdate != null)
                        {
                            StatusUpdate("Finished", ProgressBarStyle.Continuous, _info);
                        }
                        if (PercentageUpdate != null)
                        {
                            PercentageUpdate(100, 100, _info);
                        }
                    }
                    else
                    {
                        if (LogUpdate != null)
                        {
                            LogUpdate("Failed - " + logic._errorMessage, _info);
                        }
                        if (StatusUpdate != null)
                        {
                            StatusUpdate("Failed", ProgressBarStyle.Continuous, _info);
                        }
                        if (PercentageUpdate != null)
                        {
                            PercentageUpdate(-99, 100, _info);
                        }
                    }
                }
                catch (Exception e)
                {
                    try
                    {
                        if (LogUpdate != null)
                        {
                            LogUpdate("Failed - " + e, _info);
                        }
                        if (StatusUpdate != null)
                        {
                            StatusUpdate("Failed", ProgressBarStyle.Continuous, _info);
                        }
                        if (PercentageUpdate != null)
                        {
                            PercentageUpdate(-99, 100, _info);
                        }
                    }
                    catch (Exception)
                    {
                        //probably nothing left to report to
                    }
                }
            }
        }