I'm not sure about the problems with NetConnect, but you could kludge a solution by calling your program from a shell script, and wrapping it in calls to netagent connect/disconnect. Here's how I do it in my sshd start and stop scripts:
# Connect to the net first if necessary.
ifconfig eth0 1> /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
... do stuff here
if [ -f /tmp/sshd-connected-to-wifi ]; then
rm -f /tmp/sshd-connected-to-wifi
The code connects to the net if required, and disconnects later if it had been originally disconnected.