Ports
May 21, 2013, 05:08:46 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Pages: [1]
  Print  
Author Topic: WriteFile causes exception in VB.net but not VC++  (Read 2344 times)
theoracle39
Member
*
Posts: 8


« on: July 09, 2010, 04: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?
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1627


WWW
« Reply #1 on: July 09, 2010, 07: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
Logged
theoracle39
Member
*
Posts: 8


« Reply #2 on: July 10, 2010, 07: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?
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1627


WWW
« Reply #3 on: July 10, 2010, 10:59:09 am »

By ignore I meant catch the exception but take no action in the exception handler.

Jan
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!