We help IT Professionals succeed at work.
Get Started

WriteFile and CloseHandle seem to hang until further input

somnatic asked
Last Modified: 2008-01-09
So ... let's start :)

I have some USB device which reports as HID compliant Device. I can turn and push this device.

My program is written in C#, but it looks like the program lies with some of the API functions.

I can push and rotate this device and via ReadFile I can get the data (what has been done / rotated / pushed).

I should also be able to write to that device (therefore 1 (maybe 2) bytes are sent to the device).
The Problem:
When I call WriteFile with the handle at first my whole program seems to hang (I watched it in the debugger and it looks like WriteFile doesn't do anything). When I now rotate (or push)  the device (so that some data should be sent from the device to my PC) the data reaches me and WriteFiles continues (and ends with success).

The same applies for CloseHandle

I call CloseHandle -> Everything hangs -> I move the device -> CloseHandle continues and succeeds (no error)

I do the reading in a separate Thread - so could this be the problem?

Can anyone out there maybe help me ?
Watch Question
This problem has been solved!
Unlock 2 Answers and 17 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE