browse by category or date

Harian Kompas hari ini memberitakan mengenai peresmian jembatan Kelok 9 di Sumatra Barat. Sungguh berita ini membuat saya ikut bangga atas prestasi kita di dunia konstruksi.

kelok.9

Namun setelah mengamati gambar di atas beberapa lama. Saya kok jadi ragu apakah ini suatu prestasi, atau malah suatu pemborosan uang. Saya malah terpikir kenapa mereka tidak membuat jalan seperti di bawah ini?

kelok.9.1

Mohon maklum saya tidak tahu situasi geografis dari jembatan Kelok 9 ini. Mungkin para pembaca dari Sumatra Barat bisa memberi pencerahan?

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Recently I created a program which one of its task is to filter files based on their last update date.

My initial code was something like this:

var procFolder = new DirectoryInfo(ConfigurationManager.AppSettings["ProcessFolder"]);
var mdnFolder = new DirectoryInfo(procFolder.FullName + "\\mdn");
var lastWriteTime = DateTime.Parse(ConfigurationManager.AppSettings["ModifiedDate"]);
var dTarget = new DirectoryInfo(ConfigurationManager.AppSettings["targetFolder"]);

var qMdn = from c in mdnFolder.GetFiles().AsQueryable()
		   where c.LastWriteTime == lastWriteTime
		   select c;
		   
if (qMdn.Count() == 0)
	qMdn = from c in mdnFolder.GetFiles().AsQueryable()
		   where c.LastWriteTime >= lastWriteTime.AddSeconds(-1) 
				&& c.LastWriteTime <= lastWriteTime.AddSeconds(1)
		   select c;
		   
foreach (FileInfo f in qMdn)
{
	f.CopyTo(dTarget.FullName + "\\" + f.Name, true);
}

As I expected, it was slow. It is iterating the files in sequential manner. To make it faster, we need to iterate the files in parallel manner. This is where Parallel LINQ kicks ass. I’ve heard about Parallel LINQ (PLINQ) before, but I never actually tried it.

So I visited PLINQ’s webpage to find out more. Over there, the page states that PLINQ only runs on .NET 4 and above. This is sad, as I’m still stuck with Visual Studio 2008.

Is there a way to run PLINQ in .NET 3.5? With that question, Google led me to a discussion at StackOverflow. From there, I know that Reactive.NET has backported the Task Parallel Library to .NET 3.5, as Jon Skeet mentioned. To make life even easier, Omer Mor has created a nuget called TaskParallelLibrary for easy integration. This nuget contains System.Threading.dll which can be easily included in your project reference.

Once you’ve referenced it in your project, we can use .AsParallel() in our code:

var procFolder = new DirectoryInfo(ConfigurationManager.AppSettings["ProcessFolder"]);
var mdnFolder = new DirectoryInfo(procFolder.FullName + "\\mdn");
var lastWriteTime = DateTime.Parse(ConfigurationManager.AppSettings["ModifiedDate"]);
var dTarget = new DirectoryInfo(ConfigurationManager.AppSettings["targetFolder"]);

var qMdn = from c in mdnFolder.GetFiles().AsQueryable().AsParallel()
		   where c.LastWriteTime == lastWriteTime
		   select c;
		   
if (qMdn.Count() == 0)
	qMdn = from c in mdnFolder.GetFiles().AsQueryable().AsParallel()
		   where c.LastWriteTime >= lastWriteTime.AddSeconds(-1) 
				&& c.LastWriteTime <= lastWriteTime.AddSeconds(1)
		   select c;
		   
foreach (FileInfo f in qMdn)
{
	f.CopyTo(dTarget.FullName + "\\" + f.Name, true);
}

There you go. It’s easy to make Parallel LINQ available to .NET 3.5. But be warned that this method is not suported by Microsoft. If you plan to deploy this in production, Jon Skeet advises us to upgrade to .Net 4.

I hope it helps, cheers!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

hugh.laurieWe are all know Dr. Gregory House for his sarcastic remarks, brilliant deductions, petty crimes, and bleak views on humanity. Now imagine a more subdued version of him, less egocentric, more or less the same amount of sarcasm, a much nicer person and a hired gun.

He is Thomas Lang. A former Scots Guard, now working as a freelance bodyguard/man for hire. When he offered a contract to assassin someone, he unwillingly accepted it. Instead of really assassin the target, Lang tried to warned him about the assassination contract.

This is where Lang’s journey began. Follow his adventures as he hopelessly doing everything to save a girl, and accidentally prevented worldwide bloodbath.

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: