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


C# ManualResetEvent.Count方法代码示例

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


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

示例1: Inference

        public static TreeScore Inference(
            int num_bootstraps,
            InputSample[][] resamples,
            Dictionary<AST.Range, InputSample> initial_inputs,
            Dictionary<AST.Address, string> initial_outputs,
            AST.Range[] input_arr,
            AST.Address[] output_arr,
            DAG dag,
            bool weighted,
            double significance,
            ProgBar pb)
        {
            // synchronization token
            object lock_token = new Object();

            // init thread event notification array
            var mres = new ManualResetEvent[input_arr.Length];

            // init job storage
            var ddjs = new DataDebugJob[input_arr.Length];

            // init started jobs count
            var sjobs = 0;

            // init completed jobs count
            var cjobs = 0;

            // last-ditch effort flag
            bool last_try = false;

            // init score storage
            var scores = new TreeScore();

            for (int i = 0; i < input_arr.Length; i++)
            {
                try
                {
                    #region BOOTSTRAP
                    // bootstrapping is done in the parent STA thread because
                    // the .NET threading model prohibits thread pools (which
                    // are MTA) from accessing STA COM objects directly.

                    // alloc bootstrap storage for each output (f), for each resample (b)
                    FunctionOutput<string>[][] bs = new FunctionOutput<string>[initial_outputs.Count][];
                    for (int f = 0; f < initial_outputs.Count; f++)
                    {
                        bs[f] = new FunctionOutput<string>[num_bootstraps];
                    }

                    // init memoization table for input vector i
                    var memo = new BootMemo();

                    // fetch the input range TreeNode
                    var input = input_arr[i];

                    // fetch the input range COM object
                    var com = dag.getCOMRefForRange(input).Range;

                    // compute outputs
                    // replace the values of the COM object with the jth bootstrap,
                    // save all function outputs, and
                    // restore the original input
                    for (var b = 0; b < num_bootstraps; b++)
                    {
                        // lookup outputs from memo table; otherwise do replacement, compute outputs, store them in table, and return them
                        FunctionOutput<string>[] fos = memo.FastReplace(com, dag, initial_inputs[input], resamples[i][b], output_arr, false);
                        for (var f = 0; f < output_arr.Length; f++)
                        {
                            bs[f][b] = fos[f];
                        }
                    }

                    // restore the original inputs; faster to do once, after bootstrapping is done
                    BootMemo.ReplaceExcelRange(com, initial_inputs[input]);

                    // TODO: restore formulas if it turns out that they were overwrittern
                    //       this should never be the case
                    #endregion BOOTSTRAP

                    #region HYPOTHESIS_TEST
                    // cancellation token
                    mres[i] = new ManualResetEvent(false);

                    // set up job
                    ddjs[i] = new DataDebugJob(
                                dag,
                                bs,
                                initial_outputs,
                                input_arr[i],
                                output_arr,
                                weighted,
                                significance,
                                mres[i]
                                );

                    sjobs++;

                    // hand job to thread pool
                    ThreadPool.QueueUserWorkItem(ddjs[i].threadPoolCallback, i);
                    #endregion HYPOTHESIS_TEST
//.........这里部分代码省略.........
开发者ID:plasma-umass,项目名称:DataDebug,代码行数:101,代码来源:Analysis.cs

示例2: Start

        public void Start()
        {
            var controller = ConnectsterController.Instance();

            while (true)
            {
                if (_killToken)
                {
                    break;
                }

                var userList = controller.GetAllUsers();
                Log.InfoFormat("Found {0} ShopsterifyUsers, beginning sync for each user.", userList.Count);

                //Todo: add call to update sleepUntil Timestamps on users (based on how long they should sleep).
                //todo: Also throughout code, we should add points where the user should sleep
                //		such as in shopifycommunicator, if they have used up their call limit (per 10 mins)
                //		then we should sleep that user for 10 mins

                var actions = 0;
                var myJobs = new List<ConnectsterSyncJob>(userList.Count);
                var resetEvents = new ManualResetEvent[userList.Count];

                for (var i = 0; i < userList.Count; i++)
                {
                    resetEvents[i] = new ManualResetEvent(false);

                    //TODO: refactor code so it will sleep a certain user, but keep others active
                    var job = new ConnectsterSyncJob(controller, userList[i], resetEvents[i]);
                    myJobs.Add(job);
                    ThreadPool.QueueUserWorkItem(job.ThreadStart, null);
                }

                if (resetEvents.Count() > 0)
                {
                    WaitHandle.WaitAll(resetEvents);
                }

                foreach (var job in myJobs)
                {
                    Log.InfoFormat("Job({0},{1}) had {2} actions", job.myUser.ShopsterUser, job.myUser.ShopifyUser,
                                   job.actionsPerformed);
                    actions += job.actionsPerformed;
                }

                var sleepTimer = SleepTime;

                if (actions == 0)
                {
                    //Double the amount of time we sleep if there was nothing to do last time.
                    //Maxes out at 4.3 minutes and stays there until something happens.
                    if (sleepTimer < 262144)
                    {
                        sleepTimer *= 2;
                    }
                }
                else
                {
                    sleepTimer = 1024; //1 second
                }

                Log.InfoFormat("Completed {0} actions going to sleep for {1} ms.", actions, sleepTimer);
                Thread.Sleep(sleepTimer);
            }

            // ReSharper disable FunctionNeverReturns
        }
开发者ID:shopster,项目名称:NconnectSter,代码行数:67,代码来源:ConnectsterServer.cs


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