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


C# Worker.RunWorkerAsync方法代码示例

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


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

示例1: FormLoader

        public FormLoader(Plugin plugin, RecordReader stockReader, bool lazyLoading, int backgroundJobs)
        {
            if (backgroundJobs < 0)
                throw new ArgumentException("Number of bakcground jobs must be a positive integer or zero");

            sharedData = new SharedData()
            {
                Plugin = plugin,
                StockReader = stockReader,
                LazyLoading = lazyLoading,
                FormsToLoad = new BlockingCollection<Form>(new ConcurrentQueue<Form>(), 1024),
                WorkerCompleteEvent = new AutoResetEvent(false)
            };

            this.stockReader = stockReader;
            asyncLoading = backgroundJobs > 0;

            bool useStockReader = true;
            while (backgroundJobs-- > 0)
            {
                Worker worker = new Worker(sharedData, useStockReader);
                worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
                worker.RunWorkerAsync();
                workers.Add(new WorkerInfo()
                {
                    Worker = worker
                });

                // Only the first worker can use the stock reader
                useStockReader = false;
            }
        }
开发者ID:unforbidable,项目名称:patcher,代码行数:32,代码来源:FormLoader.cs

示例2: UpdateList


//.........这里部分代码省略.........
            Worker worker = new Worker(this, (cancelToken) =>
            {
                this.InvokeIfRequired(() =>
                {
                    try
                    {
                        this.BeginUpdate();
                        this.Items.Clear();
                    }
                    finally
                    {
                        this.EndUpdate();
                    }
                });

                List<ListViewItem> items = new List<ListViewItem>();

                if (this.MethodContainer is Class)
                {
                    HashSet<string> got = new HashSet<string>();

                    foreach (Method m in this.MethodContainer.CalledMethods)
                    {
                        foreach (ThrownException ex in m.UnhandledExceptions)
                        {
                            if (this.Exceptions.Contains(ex))
                            {
                                string id = ex.Method.GetId() + ex.Exception.FullName;
                                if (!got.Contains(id))
                                {
                                    got.Add(id);
                                    //ListViewItem item = MakeItem(ex, ex.Method).Item;
                                    ListViewItem item = MakeItem(ex, m).Item;
                                    items.Add(item);
                                }
                            }
                        }
                    }
                }
                else if (this.GroupByType)
                {
                    // group the exceptions by type
                    ThrownExceptionDictionary dict = new ThrownExceptionDictionary(this.Exceptions);

                    foreach (IEnumerable<ThrownException> list in dict.GetLists())
                    {
                        Type type = list.First().Exception;
                        ListViewGroup lvg = this.Groups.Add(type.FullName, type.Name);
                        list.ToList().ForEach(item => items.Add(MakeItem(item, item.Method, lvg).Item));
                    }
                }
                else
                {
                    IEnumerable<Method> methods;

                    if (this.MethodContainer is Method)
                    {

                    }
                    else
                    {
                        methods = new Method[] { this.MethodContainer as Method }.Concat(this.MethodContainer.CalledMethods);
                    }
                    foreach (ThrownException ex in this.Exceptions)
                    {
                        Method m = null;
                        if (ex.Method == this.MethodContainer)
                        {
                            m = this.MethodContainer as Method;
                        }
                        else
                        {
                            m = this.MethodContainer.CalledMethods.FirstOrDefault(md => md.UnhandledExceptions.Contains(ex));
                            if (m == null)
                            {
                                m = this.MethodContainer as Method;
                            }
                        }
                        ListViewItem item = MakeItem(ex, m).Item;
                        items.Add(item);
                    }

                }

                this.InvokeIfRequired(() =>
                {
                    try
                    {
                        this.BeginUpdate();
                        this.Items.AddRange(items.ToArray());
                    }
                    finally
                    {
                        this.EndUpdate();
                    }
                });
            });

            worker.RunWorkerAsync();
        }
开发者ID:stegru,项目名称:ExceptionExplorer,代码行数:101,代码来源:ExceptionList.cs

示例3: showCalibrationForm

        /// <summary>
        /// Kicks off the background worker to display the calibration form
        /// </summary>
        /// <param name="position">where to display the form?</param>
        /// <param name="caption">caption of the form</param>
        /// <param name="prompt">any message to display?</param>
        /// <param name="timeout">calibration timeout</param>
        /// <param name="enableConfigure">should calibration button be enabled?</param>
        private void showCalibrationForm(Windows.WindowPosition position, String caption, String prompt, int timeout, bool enableConfigure)
        {
            _bgTaskDoneEvent.Reset();
            _bgWorker = new Worker
            {
                Prompt = prompt,
                Timeout = timeout,
                Caption = caption,
                EnableConfigure = enableConfigure,
                WorkerSupportsCancellation = true,
                WorkerReportsProgress = false,
                Position = position
            };

            _bgWorker.RunWorkerCompleted += bgWorker_RunCompleted;
            _bgWorker.DoWork += bgWorker_DoWork;
            _formCreatedEvent.Reset();
            _bgWorker.RunWorkerAsync();

            _formCreatedEvent.WaitOne();
        }
开发者ID:glwu,项目名称:acat,代码行数:29,代码来源:ActuatorEx.cs


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