I've got a procedure within a class that will be running something on its own thread. Basically it's a timer that will fire periodically... well when that event fires I want to be able to handle that on a windows form. for example:

the class is a queue, when the event fires I want to fire an event handler and dequeue an item, passing that by reference through the event handler. I then want the windows form to handle the event and using that dequeued item create a listview item and add it to a list view control.

The event does fire, and the windows form does handle the event, but when I try to add the item to the control, I get a cross-thread exception. It's saying that the listview control is being accessed by another thread, but the handler is on the form's code, not the class.

Can anyone tell me what I'm doing wrong?

-SelArom

Okay I did some debugging and it seems that the thread that is running is indeed the one that I created to run inside the class. How do I make the main thread capture the event instead of that one, or can I not do that?

-SelArom

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.