本文整理汇总了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;
}
示例2: SolarLogMonitoringThread
public SolarLogMonitoringThread(String _URL, ConsoleOutputLogger COL, ConcurrentQueue<SolarLogDataSet> EventQueue, Int32 UpdateTime = 10000)
{
URL = _URL;
SolarLogUpdateTime = UpdateTime;
ConsoleOutputLogger = COL;
iQueue = EventQueue;
}
示例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;
}
示例4: Playlist
public Playlist(int maxPlayed = 4, int lowCount = 1)
{
MaxPlayed = maxPlayed;
LowPlaylistCount = lowCount;
_nextSongs = new ConcurrentQueue<Song>();
_playedSongs = new ConcurrentQueue<Song>();
}
示例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);
}
}
}
}
示例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;
});
}
示例7: SpawnerManager
public SpawnerManager()
{
this._sceneManager = null; // post init
this._spawnRequestConcurrentQueue = new ConcurrentQueue<GameObjectSpawnRequest>();
this._removeGameObjectRequestConcurrentQueue = new ConcurrentQueue<IGameObject>();
this._firstTime = true;
}
示例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);
});
}
示例9: WSSharpWebSocketEngine
internal WSSharpWebSocketEngine(WebSocket parent, string userAgent, int sendInterval)
{
_parent = parent;
_userAgent = userAgent;
_sendInterval = sendInterval;
_sendQueue = new ConcurrentQueue<string>();
}
示例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();
}
示例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));
}
示例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));
}
示例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
}
示例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);
}
示例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();
}
}
}