Archive

Posts Tagged ‘PLINQ’

C# Enterprise Library Asynchronous Logging

July 28, 2011 2 comments

We all know how slow any logging mechanism is, specially when one of the trace listeners is logging to a database. By using .NET 4.0 with it’s Parallel Library (System.Threading.Task) we can easily turn our logger to use fire-forget asynchronous operation.

 Example below uses Enterprise Library 5.0.

Suppose this is your existing LogMessage method:

Just add another method LogMessageAsync with ff code:

Now to log asynchronously just call the LogMessageAsync() method.

 

 

Advertisements

C# Parallel – Call methods with input and return values

July 25, 2011 Leave a comment

In .NET 4.0 they made it easy to start a task/process simultaneously. Code below shows how you can execute two methods with input and return values simultaneously thru the Tasks Factory in System.Threading.Task namespace.

Note: Add System.Threading.Tasks & System.Diagnostics in the using statement.

Code:

 

 

Output:

Categories: .NET Development Tags: ,

>PLINQ – Pallalel Computing Made Easy

September 9, 2010 Leave a comment

>static void Main(string[] args)

{
List<string> myCollection = new List<string>
{
“Item1”,
“Item2”,
“Item3”,
“Item4”,
“Item5”,
};


myCollection
.AsParallel()
.ForAll(item =>
{
string newItemName = string.Format(“Formatted Item:{0}_{1}”, item, System.Guid.NewGuid());
Console.WriteLine(newItemName);
}
);

Not really an intensive processing right, but atleast you get the idea.

}

Categories: .NET Development Tags: , ,
%d bloggers like this: