Closing Blocked Thread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Damien582
    New Member
    • Aug 2008
    • 9

    Closing Blocked Thread

    Hi everyone,

    I am working with a library (HIDLibrary) to read from and hid device (eHome Infraread Transceiver, aka Windows Media Center Remote) to read from a universal remote control. The library functions perfectly, even with other devices. However, my problem lies in the fact that I am running my polling function in another thread, as the library's read function blocks the thread until input is received. While my app is running, this is fine, but of course not when trying to close my app. Calling the library's CloseDevice() function does not cancel the read either. Would any of you kind people happen to know the correct way to kill a thread blocked during an IO call? I've heard of P/Invoke to TerminateThread but also read that is not recommended. Any insight would be helpful. Thank you.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Does thread.abort() work?

    Comment

    • Damien582
      New Member
      • Aug 2008
      • 9

      #3
      Thread.Abort() does not work, as the library is waiting for input from the usb device before finishing the threadstart. If I try to close the app, then press a button on the remote, it works fine. However this is not exactly preferred. I even tried setting the thread to background, but no joy.

      Comment

      • Damien582
        New Member
        • Aug 2008
        • 9

        #4
        Well I've found a solution that is at least more satisfactory. I rewrote my Reader class to be intstance based rather than a static class, and instead of running in a separate looped thread, I do an async read on the device, then close/open the device again, and run the read function again from my callback:

        private void Listen()
        {
        device.Read(new HidDevice.ReadC allback(OnDataR eceived));
        }
        private void OnDataReceived( HidDeviceData hid_data)
        {
        if (this.DataRecei ved != null){this.Data Received(this, new HIDDataEventArg s(hid_data));}
        device.CloseDev ice();
        device.OpenDevi ce();
        Listen();
        }
        This works for my form-based app to edit different remote profiles and assign actions to buttons, but will not do for my service to convert the hid data received to keystrokes using keyb_event. Any ideas? I'll gladly give my code to anyone interested, as this is a personal project, not commercial...

        Comment

        • Christian Madsen
          New Member
          • Aug 2010
          • 2

          #5
          Request for code!

          Hey Damien582!

          I know this is a long shot, but do you still have the code?

          I have a eHome Infrared Transceiver too, and i'm trying to create my own remote control on my computer, to control my infrared helicopter. ;) Pretty cool right?

          But my problem is that my code hangs at the "Read()" just like yours, but i can't get it to continue, even though i can see that it receives data, because the red led on it lights up when i press a button on my control.

          Really hope you still have your code, so i can see if i've done something wrong!

          - Christian Madsen

          Comment

          • Christian Madsen
            New Member
            • Aug 2010
            • 2

            #6
            Oh. I forgot to say. If you wanna give me the code, please send it to my email if thats what's easiest for you!
            e-mail: pixi_trix@hotma il.com

            Comment

            Working...