I use a BlockingCollection to implement a producer-consumer pattern in C# 4.0.
The BlockingCollection holds items which take up quite a lot memory. I would like to let the producer takes one item out of the BlockingCollection at a time, and process it.
I was thinking that by using foreach on BlockingCollection.GetConsumingEnumerable(...
I am trying to execute the following code and I keep getting an Index out of range exception when trying to assign array values to the list:-
int[] array = new int[1000000];
for (int i = 0; i < array.Length; i++)
{
array[i] = i;
}
List<int> list = new List<int>();
Parallel.For...
I have a method that returns a task like:
public static Task<int> SendAsync(this Socket socket, byte[] buffer, int offset, int count)
{
if (socket == null) throw new ArgumentNullException("socket");
if (buffer == null) throw new ArgumentNullException("buffer");
return Task.Factory.FromAsync<int>(
socket.BeginSend(bu...
Hi there, trying to grasp the TPL.
Just for fun I tried to create some Tasks with a random sleep to see how it was processed. I was targeting a fire and forget pattern..
static void Main(string[] args)
{
Console.WriteLine("Demonstrating a successful transaction");
Random d = new Random();
for (int i = 0; i...
I don't see the different between C#'s (and VB's) new async features, and .NET 4.0's Task Parallel Library. Take, for example, Eric Lippert's code from here:
async void ArchiveDocuments(List<Url> urls) {
Task archive = null;
for(int i = 0; i < urls.Count; ++i) {
var document = await FetchAsync(urls[i]);
if (archi...
I have a program that has a ton of sensors producing data at a fairly high rate, and consumers that need to consume it. The consumers consume at very different rates.
Since I am using IObserver/IObservable, the trivial solution was to simply create a Task for each event and wrap the OnNext() call and the data in a lamda. This worked v...