0

My USB device is communicating with my C# application once in 500ms and exchanging data(Using a timer and interrupt transfer.) So far seems Ok.

If my device is abruptly removed,(I think)windows 'device removal' message arrives only after removal is complete. But my application tries to write to my device in the meantime and throws an exception . safefilehandle closed

my FileIo.WriteFile failed.
at this time the writehandle is invalid and I closed it. WriteHandle.close
I tried by stopping next transfers but still exception throws with some other message.

The exception is sometimes thrown in some later try catch blocks. is it possible or my mistake in understanding ?

If a USB 'device write' failed as writehandle is no longer valid or present how should we tackle the exception and save the application from crashing?

Thank you

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by RoyMicro
0

And easy solution around the problem is to have a class that read/writes form/to the USB Device (and this is it's sole purpose in life)

In this class you can have a private flag, this flag can be set true or false depending on whether an exception has been thrown. Then you can bail out of your usb device class without having to worry about much else.

Edited by Ketsuekiame: n/a

0

Thanks for the suggession, I am trying different options.
Thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.