473,394 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.
Nov 8 '09 #1
5 3106
tlhintoq
3,525 Expert 2GB
Does thread.abort() work?
Nov 8 '09 #2
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.
Nov 8 '09 #3
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.ReadCallback(OnDataReceived));
}
private void OnDataReceived(HidDeviceData hid_data)
{
if (this.DataReceived != null){this.DataReceived(this, new HIDDataEventArgs(hid_data));}
device.CloseDevice();
device.OpenDevice();
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...
Nov 8 '09 #4
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
Aug 11 '10 #5
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@hotmail.com
Aug 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
12
by: MuZZy | last post by:
Hi, Sorry for a repeated post but i didn't receive an answer and will try to re-phrase my question: How do i close an additional thread from the main thread, if this additional thread is stuck...
4
by: scott | last post by:
hi all, Thx to any one that can offer me help, it will be much appreciated. iv got a multithreaded program and need to use thread synchronization. The synchronization does not have to...
4
by: Victor | last post by:
Hi everybody, could anybody kindly give me a clue in dealing with a following problem : I create a modeless dialog by means of CreateDialogIndirect(). The call executes within a thread and...
3
by: ctbfalcon | last post by:
So I have a progress bar that I would like to be diplayed as the program is working on adding a network printer. I want to do this because while the program is "thinking" the user is not sure if...
14
by: =?Utf-8?B?TWlrZVo=?= | last post by:
I have a sync socket application. The client is blocked with Socket.Receive(...) in a thread, another thread calls Socket.Close(). This unblock the blocked thread. But the socket server is still...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.