May 2005 - Posts

External USB HardDrive Adventure Trouble

 

Introduction

First, let me say that I am not really into hardware too much.  I know enough to get me around.  In other word, I know more about developing software than I know about the platform the software is going to run on, which is quite bad and I realize I need to work on that. 

The Adventure

 So, yesterday I finally decided to get myself a portable storage device.  After months of thinking which device to buy (flashdisk, ipod and other mp3 players), I decided on a USB plugable portable harddrive (only after someone actually mentioned it to me.  I wonder why I never really think of this as a viable solution before.  I know it existed.  *Shrug* sometimes the mind is working in strange ways).  I spent some time on the net browsing on sites for more information on such device.  It was decided that my budget for this is around $200 US (based on drive size - 60GB - and pricing online).  Anyhow, I tagged along with my friend who just happened to be heading to Mangga Dua.  On the way there I explained to him what it is that I am really looking for and that I've been doing my research on the net, etc.  He suggested to me a slightly different solution.   Why not buy a USB harddrive enclosure that is plugable (the internal harddrive can be changed easily) and a separate (notebook) harddrive to plug in the enclosure instead of buying a built in one.  It might cost cheaper, he said, and I went along with his suggestion. It seems to make sense to me. At Mangga Dua Mall we went store to store asking for such device.  It seems to me none of the stores that I visited have a 60GB notebook harddrive in stock.  Finally, I settled on a Rp. 975.000,- priced enclosure and a 40GB Toshiba laptop harddrive.  I was quite please with myself for not going over budget by a whole lot. :) I tend to shop on impulse sometimes which my wife hate X-).  But let's not get into that.  Hehe.  I asked the vendor if I need to install any driver for this device.  He and my friend interjected with no, no, no, on Windows XP you don't really need to install the driver.  It's all plug and play.  And so I believed them.   I mean, it's the wonderfully magical plug and play Windows XP, what can goes wrong right? :)

The Trouble

After spending hours of shopping and browsing around the mall, I arrived home, feeling eager, to try my new toy.  They said it was just a simple plug and play.  Plug both ends of the USB cord and WALLA! there is your portable storage device, magically appear as another drive on the Windows Explorer.  After all, I've seen it many times with flashdisk and bluetooth, etc.  and it always seem to work magically. Well.... guess what.... It does NOT.  The first thing that cross my mind is what a piece of crap is this that I have bought (mind you, I didn't test it when I bought it, fully trusting the vendor, hehe and I was so fully convinced on the entire Plug and Play thing).   After spending about 30-45 minutes plugging and uplugging the stupid device into multiple USB slots, I was still unable to get a drive letter in the Windows Explorer that would let me access the new freaking drive.  The funny thing is, the Plug and Play seems to work to some degree.  XP did notice the new device and display the Safely Remove Hardware in the taskbar.  I can see the device exists in the Device Manager, it has a driver attached to it, etc. but... WHERE THE F!*#( is my freaking drive letter?  WHY won't it (XP) let me access the stupid drive!!?  I was so pissed at myself for not trying it before buying it.  Now I have to go back to store (which is far far away from where I live) and return it.  What a waste of time THAT going to be. 

The Solution

In an effort to calm myself down I tried to distract myself by reading the ASP.NET 2.0 Quickstart that I installed a while back.  And then... DING!... It dawned on me that perhaps I have to do something else from XP to make the device accessible with drive letter.  My memory raced back to the long forgotten occassion when I needed to add an internal harddrive to my machine.  And so, trusting the memory, I raced the mouse toward the Administrative Tools menu item, clicked!, and to the Computer Management item, clicked!.  Walla! there it is... the Disk Management Tool!!!.  Lo and behold, the freaking drive exists there as Disk 2 Basic 37.25GB unformatted space.  I didn't know if I should start cursing or jumping with joy.  And so  from the tool I formatted the new drive and assign it to Z:.  After waiting a while for the drive to format, I finally get to see and use my new 40GB portable Z: drive.  Yay!

The Moral of the Story

Why don't you figure that one out by yourself.  I am tired *yawn*.

Ps.

The story is a bit exaggerated for your amusement, but more or less that's how it went.  Enjoy.

Share this post: | | | |
Posted by Jimmy Chandra | 1 comment(s)
Filed under: ,

Process, ProcessStartInfo and Deadlock

A while back I was working with System.Diagnostic.Process and System.Diagnostic.ProcessStartInfo classes to automate Oracle data import / export.  We (development team) decided to use Oracle SQLLDR and SQLPLUS tools that would be called from inside the main application.  And so it went, after testing out the new Import and Export process with small data samples, the application seems to be working okay.  However, when we tested the process with some real data from the client, sometimes the process seems to just hang there on occassion, never wanting to exit the process. I had to literally killed the “offending” process and then the application will continue on its merry way.   I was practically baffled with this “bug”.  I know somewhere in the process it is causing a deadlock but I was not quite sure where to look for it.  After a couple of days spent on digging and scrounging for articles on the matter on the Internet, I finally found the culprit here.

It turned out that the I had instructed my instance of Process class to WaitForExit indefinitely (until the actual process is done), while setting the ProcessStartInfo instance RedirectStandardOutput property to True, so it was waiting for the actual process to exit, but the actual process itself was waiting for my Process class instance to do “stuffs” with the output that it's producing before it can go further.  In this case, the amount of data passing through the pipe did present a problem (causing the deadlock). So they were happily waiting for each other to do stuffs first. 

Off the topic, this reminds me of two very polite drivers at a crossroad / intersection, driving on opposite site (north and south), one wanting to go to the west and the other to the east and both of them trying to give way to the other driver to go ahead first.  Hahaha. 

“You go first, please”, said one. 
“No, please, go ahead first”, said the other and it goes on indefinitely. Grin. 

Don't you wish they'll be more polite drivers like this in Jakarta? hehe.  Sorry, getting sick of getting cut off left and right and people who just can't obey the traffic rules (This also means all of you who are making your own lane when there is not supposed to be any, driving on the shoulder of the road in the Toll, etc.  Grrr.).  On more relevant things to Jakarta's traffic characteristic... say traffic deadlock caused by selfish motorists (that includes motorbikes, cars, traffic transports, etc.) that just won't  wait for their turn to go, instead blocking traffics as they pursue their own selfish purpose.  Nuff said.  Again, I apologize for ranting, but I did add “Life in General“ as a topic for my blog :-p.  And so I digress.

Back to the code...

And so, as the article I linked on top said, it turned out the solution is make the Process class instance to ReadToEnd before issuing the WaitForExit command as described in the example in the link. This will let the instance to clean up the pipe so more can come through it from the actual process, thus allowing the process to be a lot more “smoother“.

I hope this little story is useful to someone and helped them spend a little less time digging around on similar problem and be more productive.  Enjoy!

Share this post: | | | |
Posted by Jimmy Chandra | with no comments
Filed under: