PORTS Forum
Ports and Interfaces => USB => Topic started by: theoracle39 on July 09, 2010, 05:12:29 pm
-
If I detect a USB device, unplug it, and then try to write to the device WriteFile causes an exception in VB.net. If I run the same code in VC++ it returns WriteFile as false as it should. Why does the function work differently in one language than the other? How do I get WriteFile to return as false in VB.net if a USB device is suddently unplugged?
-
The exception is giving you useful information - you can no longer communicate with the device because it's no longer attached or other communication problems. If you don't need the information, catch and otherwise ignore the exception.
Jan
-
If I ignore the exception then the program crashes with the message ObjectDisposedException was unhandled by user code. I think this exception either needs to be prevented from happening or I need to be able to deal with it once it happens. Any suggestions?
-
By ignore I meant catch the exception but take no action in the exception handler.
Jan