Hi, = The problem is in WinUsbDevice.CloseDeviceHandle(): if (!(myDevInfo.deviceHandle.IsInvalid)){ since myDevInfo.deviceHandle is null. You can fix this by testing the = deviceHandle for null. internal void CloseDeviceHandle() { if (myDevInfo.deviceHandle !=3D null) { try { if (!(myDevInfo.deviceHandle.IsInvalid)) { FileIO.CloseHandle(myDevInfo.deviceHandle); } // Free resources. WinUsb_Free(myDevInfo.winUsbHandle); } catch (Exception ex) { throw; } } } = The real problem is that the try/catch is rethrown without handling it whic= h is = the same as not having any try/catch at all. Remove the throw and it will a= lso = work. I am not sure why you would rethrow without doing anything with the = exception instead of not catching it at all. /Ruben > I admit I have not much ideas when it comes to C# and Windows GUI program= ming. > Now here is the problem, Jan Axelson has written the USB PIC firmware and= the > host program (in C# and VB.net) as an example to test WinUSB. > = > I have tried the host software and the firmware and they seem to work > fine except one bug. If I do nothing and close the program, the program > will raise an unhandled exception. > = > Download: > http://www.lvr.com/winusb.htm > = > Detailed description of the problem: > http://forum.microchip.com/tm.aspx?m=3D339511 > = > I suppose Jan Axelson will solve the problem sooner or later. But > I am thinking this must be not a complicated problem and I'd like > to solve it as a learning exercise. But it proved to be more difficult > than I thought. Any ideas? > = > By the way, I have written libusb based program to test the firmware > under Linux and the program runs fine. > http://forum.microchip.com/tm.aspx?m=3D340892 > = > = > Regards, > Xiaofan > -- = > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124, 200 39 Malm=F6, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist