Пример #1
0
        /// <summary>
        /// Starts the block type compilation thread.
        /// </summary>
        private static void StartBlockTypeCompilationThread()
        {
            BlockTypeCompilationThread = new Thread(() =>
            {
                // Set to background thread so that this thread doesn't prevent Rock from shutting down.
                Thread.CurrentThread.IsBackground = true;

                // Set priority to lowest so that RockPage.VerifyBlockTypeInstanceProperties() gets priority
                Thread.CurrentThread.Priority = ThreadPriority.Lowest;

                Stopwatch stopwatchCompileBlockTypes = Stopwatch.StartNew();

                // get a list of all block types that are used by blocks
                var allUsedBlockTypeIds = new BlockTypeService(new RockContext()).Queryable()
                                          .Where(a => a.Blocks.Any())
                                          .OrderBy(a => a.Category)
                                          .Select(a => a.Id).ToArray();

                // Pass in a CancellationToken so we can stop compiling if Rock shuts down before it is done
                BlockTypeService.VerifyBlockTypeInstanceProperties(allUsedBlockTypeIds, _threadCancellationTokenSource.Token);

                Debug.WriteLine(string.Format("[{0,5:#} seconds] All block types Compiled", stopwatchCompileBlockTypes.Elapsed.TotalSeconds));
            });

            BlockTypeCompilationThread.Start();
        }