autoresetevent
// Simplified example. Check http://www.albahari.com/threading/part2.aspx
// for detailed explanations of this and other syncronizing constructs
private readonly AutoResetEvent _signal = new AutoResetEvent(false);
private readonly ConcurrentQueue<Something> _queue = new ConcurrentQueue<Something>();
// this method can be called by one or more threads simultaneously
// (although the order of enqueued items cannot be known if many threads are competing)
void ProduceItem(Something s)
{
_queue.Enqueue(s); // enqueue item for processing
_signal.Set(); // signal the consumer thread if it's waiting
}
// this loop should be running on a separate thread.
void ConsumerLoop()
{
while (!_ending)
{
// block until producer signals us
_signal.WaitOne();
// process whatever is enqueued
Something s = null;
while (!_ending && _concurrentQueue.TryDequeue(out s))
{
Process(s);
}
}
}
Also in C#:
- unity3d quaternion add 90 degrees
- c# anonymous class
- how to move clipping planes C# in unity
- c# merge two xml files
- c# adding to a list
- C# delegate
- c# string array
- c# how to refresh your binding source
- creating a c# class
- cshtml foreach
- dynamic convert type c#
- loop through an enum c#
- sort c#
- c# md5 string
- disable button in android studio
- c# string to float
- math class C# exponents
- c# initialize array
- asp.net render control to string
- unity accessing 2d pointlight from c# script
- how to change player cursor c# script unity
- c# create new thread
- unity mobile controls
- unity multiplayer