How do you handle events raised by a seperate thread?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 54
Reputation: SelArom is an unknown quantity at this point 
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Junior Poster in Training

How do you handle events raised by a thread in a seperate class?

 
0
  #1
May 10th, 2006
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
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 54
Reputation: SelArom is an unknown quantity at this point 
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Junior Poster in Training

Re: How do you handle events raised by a seperate thread?

 
0
  #2
May 10th, 2006
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
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC