PORTS Forum

Ports and Interfaces => USB => Topic started by: theoracle39 on July 09, 2010, 05:12:29 pm

Title: WriteFile causes exception in VB.net but not VC++
Post 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?
Title: Re: WriteFile causes exception in VB.net but not VC++
Post by: Jan Axelson on July 09, 2010, 08:39:50 pm
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
Title: Re: WriteFile causes exception in VB.net but not VC++
Post by: theoracle39 on July 10, 2010, 08:41:06 am
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?
Title: Re: WriteFile causes exception in VB.net but not VC++
Post by: Jan Axelson on July 10, 2010, 11:59:09 am
By ignore I meant catch the exception but take no action in the exception handler.

Jan