Beispiel #1
0
        /// <summary>
        /// Processes any block analysis on the given block.
        /// </summary>
        /// <param name="block">The block.</param>
        public async void ProcessBlockAnalysis(Block block)
        {
            // If we don't have any analysis controllers, we don't have to do anything.
            if (BlockAnalyzers.Count == 0)
            {
                return;
            }

            // Keep track of the running tasks so we can wait for them to finish
            // (if needed).
            Interlocked.Increment(ref tasksRunning);

            try
            {
                // Grab information about the block inside a read lock.
                int blockVersion;
                HashSet <IBlockAnalyzerProjectPlugin> analysis;

                using (block.AcquireBlockLock(RequestLock.Read))
                {
                    blockVersion = block.Version;
                    analysis     = block.GetAnalysis();
                }

                // Create a background task that will analyze the block. This will return
                // false if the block had changed in the process of analysis (which would
                // have triggered another background task).
                var analyzer = new BlockAnalyzer(
                    block, blockVersion, BlockAnalyzers, analysis);
                Task task = Task.Factory.StartNew(analyzer.Run);

                // Wait for the task to complete in the background so we can then
                // decrement our running counter.
                await task;
            }
            finally
            {
                // Decrement the counter to keep track of running tasks.
                Interlocked.Decrement(ref tasksRunning);
            }
        }
		/// <summary>
		/// Processes any block analysis on the given block.
		/// </summary>
		/// <param name="block">The block.</param>
		public async void ProcessBlockAnalysis(Block block)
		{
			// If we don't have any analysis controllers, we don't have to do anything.
			if (BlockAnalyzers.Count == 0)
			{
				return;
			}

			// Keep track of the running tasks so we can wait for them to finish
			// (if needed).
			Interlocked.Increment(ref tasksRunning);

			try
			{
				// Grab information about the block inside a read lock.
				int blockVersion;
				HashSet<IBlockAnalyzerProjectPlugin> analysis;

				using (block.AcquireBlockLock(RequestLock.Read))
				{
					blockVersion = block.Version;
					analysis = block.GetAnalysis();
				}

				// Create a background task that will analyze the block. This will return
				// false if the block had changed in the process of analysis (which would
				// have triggered another background task).
				var analyzer = new BlockAnalyzer(
					block, blockVersion, BlockAnalyzers, analysis);
				Task task = Task.Factory.StartNew(analyzer.Run);

				// Wait for the task to complete in the background so we can then
				// decrement our running counter.
				await task;
			}
			finally
			{
				// Decrement the counter to keep track of running tasks.
				Interlocked.Decrement(ref tasksRunning);
			}
		}