Hi lzhao2013,
At first sight your algorithm seems ok to me.
To be honest I have never encountered VIX_E_HOST_NETWORK_CONN_REFUSED so far. Maybe you could get a better understanding why the connection is actually refused by investigating the server logs. See Modifying the Log Level to Obtain Detailed Information for increasing log level output.
Further could you kindly provide more information on your environment, i.e. versions fo VDDK, ESX/ESXi, vCenter etc. and also log output could be interesting.
Once there was a discussion also related to locks. Maybe you want to check that out and see if it could be of any help.
--
Thomas G.