Sunday, August 29, 2010

C# - Object is currently in use elsewhere

Why can't Microsoft give better description of the exception??

For this message, System.InvalidOperationException: Object is currently in use elsewhere.

Does this message make sense to you by itself? Which object? Where?

When you see this message during Graphics operations, the object may be referring to the Pen or Brush which you are using for drawing. It seems that Graphics operation is not thread safe. The same pen or brush cannot be use when different threads are rendering on different Graphics. Simply, pen and brush cannot be shared across multiple treads.


Wednesday, August 25, 2010

Unable to delete file or folder due to deny access or lock up

This is really the most irritating thing when it happens. You have a file or folder that are being lock up or deny access. You cannot delete it or rename it or do anything to it.

There are program in the market declaring that it will helps to delete lock up files or folder. However, it will not work most of time.

Actually, chkdsk utility application may be the best recovering tool and it is from Microsoft. It will re-index and repair your disk. By re-indexing the disk drive, chkdsk will delete error entry as well.

chkdsk /f may save your day.

For me, my external harddisk disconnect while saving file. As a result, some files are locked and is deny access by WinXP. chkdsk /f will not work as well as WinXP complaints that the harddrive is being used by other processes.

Don't give up.

If you have Win7, that may be your next resort to fix your harddisk. Somehow, chkdsk /f in Win7 version helps me to repair my external harddisk. Now, I can use my harddisk as usual.

Wednesday, August 11, 2010

MS Outlook 2007 - Cannot open the Outlook window Error

A quick and simple fix that work for me is

Start->run..then type the following -> "Outlook.exe /resetnavpane"

Thursday, August 5, 2010

C# - Invoke vs BeginInvoke

From Microsoft

BeginInvoke - Executes a delegate asynchronously on the thread that the control's underlying handle was created on.

Invoke - Executes the specified delegate on the thread that owns the control's underlying window handle.

Most often, we will use these with delegate, especially, to prevent cross thread exception when you are trying to access UI components with another thread.

From their definition, BeginInvoke is a asynchronous version of Invoke. Although you may not take it to heart at first glance, you will encounter their different when you are playing around with it.

Invoke, since it is synchronous, it will ask the UI thread to do the delegate job and wait for it returns.

BeginInvoke, since it is asynchronous, it will post the delegate job to UI thread and schedule it for a time to execute while it will continue to do it current job.

The complication is Invoke may cause deadlock situation if you are not careful with your code

Imagine, thread 1 access to UI thread, and now, the UI thread wants to access thread 1 for some logic calculation. Since thread 1 is waiting for UI thread to return, a deadlock occurs.

Also, Invoke causes OS to context switch immediately. If you constantly calling Invoke, it will hamper your application performance.

But, on the other hand, BeginInvoke schedule your delegate method to be done some time in the future. Thus, it is not suitable for time-sensitive situation that execution delay is not tolerable.

Sunday, August 1, 2010

Java - ThreadMXBean

Java Management really make debugging easier. However, with IDE such as Eclipse, we may not use them in development environment.

But, if you want to debug in a remote environment whereby you have difficulty attaching your Eclipse debugger to the machine, you may appreciate Java Management Tools.

For this part, I will mention about Thread management

ThreadMXBean - The management interface for the thread system of the Java virtual machine.


This management class give you information about all the threads within the JVM. You can use it to provide deadlock information, thread CPU usage, detail thread stack trace etc..

The best part of it, you can write the code as jsp and simple attach the jsp to your remote server. This way, you can create your much desired remote debugging web tools and you can access real-time debugging information via browser at any location.

Sample to calculate CPU usage and thread stacktrace.