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


C# IProgress.Increment方法代码示例

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


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

示例1: ExecuteExperiment

        /// <summary>
        /// Executes the experiment.
        /// </summary>
        /// <param name="progress">The progress.</param>
        public void ExecuteExperiment(IProgress progress)
        {
            try
            {
                bool successful = true;
                string endMessage = Messages.ExperimentRunnerSuccessMessage;

                OnExperimentStarted();

                if (m_runnableExperiment.IsEmpty == false)
                {
                    if (progress != null)
                    {
                        progress.Reset();
                        progress.NumSteps = m_runnableExperiment.Nodes.Count;
                        // Start at 1 so user can tell something is happening.
                        progress.Increment();
                        progress.CurrentStatus = Messages.ProgressExperimentProcessing;
                    }

                    // collection of nodes currently executing
                    ActiveNodesList currentActiveNodesList = new ActiveNodesList(m_runnableExperiment.TerminateExperimentExecutionResetEvent);

                    // collection of nodes pending to be started
                    Queue<RunnableNode> pendingNodesToBeRun = new Queue<RunnableNode>();
                    
                    // enqueue start node
                    pendingNodesToBeRun.Enqueue(m_runnableExperiment.StartNode);

                    bool end = false;
                    while (!end) //until end component is not completed
                    {
                        //activate all pending nodes
                        while (pendingNodesToBeRun.Count > 0)
                        {
                            RunnableNode node = pendingNodesToBeRun.Dequeue();

                            if (currentActiveNodesList.Contains(node) == false)
                            {
                                RunnableNodeThreadArgs args = new RunnableNodeThreadArgs { ExperimentRunner = this };
                                var resetEvent = node.Run(args);

                                currentActiveNodesList.Add(node, resetEvent);
                            }
                        }

                        if (currentActiveNodesList.Count > 0)
                        {
                            //wait for any node to be completed
                            int index = WaitHandle.WaitAny(currentActiveNodesList.NodeResetEvents);

                            //the index 0 is the termination signal... if the index is higher than zero then process the completed node
                            if (index > 0)
                            {
                                RunnableNode completedNode = currentActiveNodesList.TakeOutNode(index);

                                if (progress != null)
                                {
                                    progress.Increment();
                                }

                                // if experiment runner reaches end node, then prepare to exit the experiment runner
                                if (completedNode.Equals(m_runnableExperiment.EndNode))
                                {
                                    end = true;

                                    // if there are any other nodes still running other than end node
                                    if (currentActiveNodesList.Count > 1)
                                    {
                                        successful = false;
                                        endMessage = Messages.ExperimentRunnerErrorMessage;
                                        TerminateExperimentExecution(); //send signal terminate in case sth else in sub level experiment is running
                                        NLog.LogManager.GetCurrentClassLogger().Error(Messages.ExperimentRunnerEarlyTerminationErrorMessage);
                                    }
                                }
                                else
                                {
                                    // send one token to all successor nodes
                                    foreach (RunnableNode successorNode in completedNode.NextNodes)
                                    {
                                        //sends token; method will return true if successor node is ready to be run
                                        bool readyToRun = successorNode.SendToken();

                                        if (readyToRun)
                                        {
                                            //add node to the pending nodes to be activated
                                            pendingNodesToBeRun.Enqueue(successorNode);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //EXECUTED ON SIGNAL TERMINATED
                                // If any node signal TERMINATE for any reason, we shut down the experiment and stop processing new nodes.
                                end = true;
//.........这里部分代码省略.........
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:101,代码来源:ExperimentRunner.cs


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