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


C# ConcurrentQueue类代码示例

本文整理汇总了C#中ConcurrentQueue的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentQueue类的具体用法?C# ConcurrentQueue怎么用?C# ConcurrentQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: FillOne

 public static byte[] FillOne(ConcurrentQueue<Operation> writeQueue, ConcurrentQueue<Operation> readQueue)
 {
     Operation op;
     if (!writeQueue.TryDequeue(out op)) return new byte[0];
     readQueue.Enqueue(op);
     return op.Packet;
 }
开发者ID:sdether,项目名称:Ketchup,代码行数:7,代码来源:Buffer.cs

示例2: SolarLogMonitoringThread

		public SolarLogMonitoringThread(String _URL, ConsoleOutputLogger COL, ConcurrentQueue<SolarLogDataSet> EventQueue, Int32 UpdateTime = 10000)
		{
			URL = _URL;
			SolarLogUpdateTime = UpdateTime;
			ConsoleOutputLogger = COL;
			iQueue = EventQueue;
		}
开发者ID:pereritob,项目名称:hacs,代码行数:7,代码来源:SolarLogMonitoringThread.cs

示例3: LogTextWriter

 public LogTextWriter(string filePath, string prefix = null, string suffix = null, string newline = "\n")
 {
     _outputQueue = new ConcurrentQueue<string>();
     _outputRun = 1;
     _outputThread = new Thread(() =>
     {
         string o;
             using (FileStream _fs = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
             {
         _innerWriter = new StreamWriter(_fs);
         _innerWriter.NewLine = newline;
         while (Thread.VolatileRead(ref _outputRun) == 1 || _outputQueue.Count > 0)
         {
             if (_outputQueue.Count > 0)
             {
                 while (_outputQueue.TryDequeue(out o))
                     _innerWriter.Write(o);
                 _innerWriter.Flush();
             }
             else
                 Thread.Sleep(_outputThreadDelay);
         }
     //				_fs.Close();
         _innerWriter.Close();
             }
     });
     _outputThread.Priority = ThreadPriority.BelowNormal;
     _outputThread.Start();
     _prefix = prefix;
     _suffix = suffix;
 }
开发者ID:jbowwww,项目名称:ArtefactService,代码行数:31,代码来源:LogTextWriter.cs

示例4: Playlist

 public Playlist(int maxPlayed = 4, int lowCount = 1)
 {
     MaxPlayed = maxPlayed;
     LowPlaylistCount = lowCount;
     _nextSongs = new ConcurrentQueue<Song>();
     _playedSongs = new ConcurrentQueue<Song>();
 }
开发者ID:TingPing,项目名称:elpis,代码行数:7,代码来源:Playlist.cs

示例5: ConsumerQueue

 public void ConsumerQueue()
 {
     ConcurrentQueue<User> consumerQueue;
     User user;
     int allcount = 0;
     Stopwatch watch = Stopwatch.StartNew();
     while (true)
     {
         _dataEvent.WaitOne();
         if (!_currentQueue.IsEmpty)
         {
             _currentQueue = (_currentQueue == _writeQueue) ? _readQueue : _writeQueue;
             consumerQueue = (_currentQueue == _writeQueue) ? _readQueue : _writeQueue;
             while (!consumerQueue.IsEmpty)
             {
                 while (!consumerQueue.IsEmpty)
                 {
                     if (consumerQueue.TryDequeue(out user))
                     {
                         FluentConsole.White.Background.Red.Line(user.ToString());
                         allcount++;
                     }
                 }
                 FluentConsole.White.Background.Red.Line($"当前个数{allcount.ToString()},花费了{watch.ElapsedMilliseconds.ToString()}ms;");
                 System.Threading.Thread.Sleep(20);
             }
         }
     }
 }
开发者ID:yjqGitHub,项目名称:DoubleQueueTest,代码行数:29,代码来源:DoubleQueue.cs

示例6: CheckinScript

		public void CheckinScript(ScriptedPatchRequest request, Jint.JintEngine context)
		{
			CachedResult value;
			if (cacheDic.TryGetValue(request, out value))
			{
				if (value.Queue.Count > 20)
					return;
				value.Queue.Enqueue(context);
				return;
			}
			cacheDic.AddOrUpdate(request, patchRequest =>
			{
				var queue = new ConcurrentQueue<Jint.JintEngine>();
				queue.Enqueue(context);
				return new CachedResult
				{
					Queue = queue,
					Timestamp = SystemTime.UtcNow,
					Usage = 1
				};
			}, (patchRequest, result) =>
			{
				result.Queue.Enqueue(context);
				return result;
			});
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:26,代码来源:ScriptsCache.cs

示例7: SpawnerManager

 public SpawnerManager()
 {
     this._sceneManager = null; // post init
     this._spawnRequestConcurrentQueue = new ConcurrentQueue<GameObjectSpawnRequest>();
     this._removeGameObjectRequestConcurrentQueue = new ConcurrentQueue<IGameObject>();
     this._firstTime = true;
 }
开发者ID:ErPanfi,项目名称:ProjectHCI,代码行数:7,代码来源:SpawnerManager.cs

示例8: SetUp

        protected override void SetUp()
        {
            _activator = Using(new BuiltinHandlerActivator());

            _waitedSeconds = new ConcurrentQueue<double>();

            _rebusConfigurer = Configure.With(_activator)
                .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "test backoff"))
                .Options(o =>
                {
                    o.SetBackoffTimes(TimeSpan.FromSeconds(0.2), TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(1));

                    o.Decorate<ITransport>(c =>
                    {
                        var transport = c.Get<ITransport>();
                        var transportTap = new TransportTap(transport);

                        transportTap.NoMessageReceived += () =>
                        {
                            var elapsedSinceStart = DateTime.UtcNow - _busStartTime;
                            var elapsedSeconds = Math.Round(elapsedSinceStart.TotalSeconds, 1);
                            _waitedSeconds.Enqueue(elapsedSeconds);
                        };

                        return transportTap;
                    });

                    o.SetMaxParallelism(10);
                    o.SetNumberOfWorkers(1);
                });
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:31,代码来源:TestCustomizedBackoffTime.cs

示例9: WSSharpWebSocketEngine

		internal WSSharpWebSocketEngine(WebSocket parent, string userAgent, int sendInterval)
		{
			_parent = parent;
			_userAgent = userAgent;
			_sendInterval = sendInterval;
			_sendQueue = new ConcurrentQueue<string>();
		}
开发者ID:Goobles,项目名称:Discord.Net,代码行数:7,代码来源:WebSocket.WebSocketSharp.cs

示例10: ExSocket

 /// <summary>
 /// Initializes a new instance of the <see cref="ZyGames.Framework.RPC.Sockets.ExSocket"/> class.
 /// </summary>
 /// <param name="socket">Socket.</param>
 public ExSocket(Socket socket)
 {
     HashCode = Guid.NewGuid();
     sendQueue = new ConcurrentQueue<SocketAsyncResult>();
     this.socket = socket;
     InitData();
 }
开发者ID:GamesDesignArt,项目名称:UniversalCommon,代码行数:11,代码来源:ExSocket.cs

示例11: LogFileSearch

        public LogFileSearch(ITaskScheduler taskScheduler, ILogFile logFile, string searchTerm, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
                throw new ArgumentNullException("taskScheduler");
            if (logFile == null)
                throw new ArgumentNullException("logFile");
            if (string.IsNullOrEmpty(searchTerm))
                throw new ArgumentException("searchTerm may not be empty");

            _logFile = logFile;
            _filter = new SubstringFilter(searchTerm, true);
            _matches = new List<LogMatch>();
            _syncRoot = new object();
            _listeners = new LogFileSearchListenerCollection(this);
            _pendingModifications = new ConcurrentQueue<LogFileSection>();
            _scheduler = taskScheduler;

            const int maximumLineCount = 1000;
            _maximumWaitTime = maximumWaitTime;
            _logLinesBuffer = new LogLine[maximumLineCount];
            _matchesBuffer = new List<LogLineMatch>();
            _logFile.AddListener(this, _maximumWaitTime, maximumLineCount);

            _task = _scheduler.StartPeriodic(FilterAllPending,
                                             TimeSpan.FromMilliseconds(100),
                                             string.Format("Search {0}", logFile));
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:27,代码来源:LogFileSearch.cs

示例12: createPersonsLots

        public Tuple<Dictionary<int, int>, Dictionary<string, int>, Dictionary<int, JObject>> createPersonsLots(Dictionary<string, Dictionary<string, NomValue>> noms)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken ct = cts.Token;

            ConcurrentQueue<int> personIds = new ConcurrentQueue<int>(this.getPersonIds());

            ConcurrentDictionary<int, int> personIdToLotId = new ConcurrentDictionary<int, int>();
            ConcurrentDictionary<string, int> personEgnToLotId = new ConcurrentDictionary<string, int>();
            ConcurrentDictionary<int, JObject> personLotIdToPersonNom = new ConcurrentDictionary<int, JObject>();

            Utils.RunParallel("ParallelMigrations", ct,
                () => this.personLotCreatorFactory().Value,
                (personLotCreator) =>
                {
                    using (personLotCreator)
                    {
                        personLotCreator.StartCreating(noms, personIds, personIdToLotId, personEgnToLotId, personLotIdToPersonNom, cts, ct);
                    }
                })
                .Wait();

            timer.Stop();
            Console.WriteLine("Person lot creation time - {0}", timer.Elapsed.TotalMinutes);

            return Tuple.Create(
                personIdToLotId.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
                personEgnToLotId.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
                personLotIdToPersonNom.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
        }
开发者ID:MartinBG,项目名称:Gva,代码行数:33,代码来源:Person.cs

示例13: Iterate

 private static Map Iterate(ConcurrentQueue<Tuple<Map, char>> queue, Tree tree)
 {
     Tuple<Map, char> var;
     while (!queue.TryDequeue(out var)) System.Threading.Thread.Sleep(5);
     var currentMap = var.Item1;
     var cars = currentMap.Parse();
       //Console.WriteLine("Checking:\n" + currentMap);
     if (cars.ContainsKey(Globals.TargetCar) && cars[Globals.TargetCar].Item1.Equals(targetLocation))
         return currentMap;
     foreach (var kvp in cars)
         if (kvp.Key != var.Item2) {
             Map move;
             bool horizontal = kvp.Value.Item3 == Direction.Right;
             for (int i = 1; i <= (horizontal ? kvp.Value.Item1.X : kvp.Value.Item1.Y); i++) {
                 move = currentMap.makeMove(kvp.Key, kvp.Value.Item1, kvp.Value.Item3.Invert(), kvp.Value.Item2, i);
                 if (move != null) {
                     NewMethod(queue, tree, currentMap, kvp, move);
                 }
                 else break;
             }
             for (int i = 1; i < (horizontal ? map.map.GetLength(0) - kvp.Value.Item1.X : map.map.GetLength(1) - kvp.Value.Item1.Y); i++) {
                 move = currentMap.makeMove(kvp.Key, kvp.Value.Item1, kvp.Value.Item3, kvp.Value.Item2, i);
                 if (move != null) {
                     NewMethod(queue, tree, currentMap, kvp, move);
                 }
                 else break;
             }
         }
     if (queue.Count == 0) return Globals.NoSolutions; // We don't have anything to add
     return null; // no solution found yet
 }
开发者ID:kutagh,项目名称:RushHour,代码行数:31,代码来源:Program.cs

示例14: Fill

        private static List<byte> Fill(List<byte> buffer, ConcurrentQueue<Operation> writeQueue, ConcurrentQueue<Operation> readQueue)
        {
            Operation op;

            //at this point there should never be nothing in the queue, but just in case
            if (!writeQueue.TryPeek(out op))
                return buffer;

            //check if adding the next item in the queue would overflow the buffer
            if (op.Packet.Length + buffer.Count > _bufferLength)
                return buffer;

            //again, if you peeked at it, it should still be here, so you should never hit this
            if (!writeQueue.TryDequeue(out op))
                return buffer;

            //make sure these two operations happen as transaction
            var currentIndex = buffer.Count;
            try
            {
                buffer.AddRange(op.Packet);
                readQueue.Enqueue(op);
            }
            catch
            {
                //roll it back
                buffer.RemoveRange(currentIndex, op.Packet.Length);
                writeQueue.Enqueue(op);
            }

            //continue filling the buffer until it's full
            return Fill(buffer, writeQueue, readQueue);
        }
开发者ID:sdether,项目名称:Ketchup,代码行数:33,代码来源:Buffer.cs

示例15: RunProcess

        public void RunProcess(Action<Action<StringDictionary>> process, string[] servicePrincipal)
        {
            var key = Guid.NewGuid().GetHashCode().ToString("X");
            string @namespace = servicePrincipal.Any() ? "Global" : "Local";

            _memoryManager.Initialise(@namespace, key, servicePrincipal);
            _messageQueue = new ConcurrentQueue<byte[]>();

            using (_mcb = new MemoryManager.ManagedCommunicationBlock(@namespace, key, MaxMsgSize, -1, servicePrincipal))
            using (var processMgmt = new AutoResetEvent(false))
            using (var queueMgmt = new AutoResetEvent(false))
            using (var environmentKeyRead = new AutoResetEvent(false))
            {
                var handles = new List<WaitHandle> { processMgmt, _mcb.ProfilerRequestsInformation };

                ThreadPool.QueueUserWorkItem(
                    SetProfilerAttributes(process, key, @namespace, environmentKeyRead, processMgmt));
                ThreadPool.QueueUserWorkItem(SaveVisitData(queueMgmt));

                // wait for the environment key to be read
                if (WaitHandle.WaitAny(new WaitHandle[] {environmentKeyRead}, new TimeSpan(0, 0, 0, 10)) != -1)
                {
                    ProcessMessages(handles.ToArray());
                    queueMgmt.WaitOne();
                }
            }
        }
开发者ID:jayrowe,项目名称:opencover,代码行数:27,代码来源:ProfilerManager.cs


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