Click here to Skip to main content
15,906,567 members
Home / Discussions / C#
   

C#

 
QuestionHow to handle this Event ? Pin
Paramu197318-Jan-12 23:01
Paramu197318-Jan-12 23:01 
AnswerRe: How to handle this Event ? PinPopular
Eddy Vluggen19-Jan-12 0:31
professionalEddy Vluggen19-Jan-12 0:31 
GeneralRe: How to handle this Event ? Pin
Paramu197320-Jan-12 18:43
Paramu197320-Jan-12 18:43 
GeneralRe: How to handle this Event ? Pin
Eddy Vluggen21-Jan-12 1:40
professionalEddy Vluggen21-Jan-12 1:40 
AnswerRe: How to handle this Event ? PinPopular
BobJanova19-Jan-12 1:01
BobJanova19-Jan-12 1:01 
GeneralRe: How to handle this Event ? Pin
Paramu197320-Jan-12 18:44
Paramu197320-Jan-12 18:44 
QuestionThreading and events Pin
Giorgi Nistor18-Jan-12 21:57
Giorgi Nistor18-Jan-12 21:57 
AnswerRe: Threading and events Pin
BobJanova19-Jan-12 0:57
BobJanova19-Jan-12 0:57 
1. From thWorkerB I raise an event intended to be caught by subscriber CModuleA class.
Inside CModuleA it is the handling event funtion.
The execution of the thWorkerB thread remain blocked inside the eventHandling function from CModuleA until it finishes?

Yes. Unless you delegate execution to another thread, event handlers run in the thread from which you called them. An event handler should never do anything which will take a long time for this reason (except in cases where you are happy for that component to have its queue stalled); you should post messages onto a queue which is handled by another thread, or something similar, and return as quickly as possible.

2. How is exactly this send event handled? In what context is it done?

Methods called through a delegate are in the same execution context as the method from which they were called, similar to a normal method call.

3. You can use Invoke to execute across threads if you have a Control to call it on, or you have a Dispatcher to hand (WPF). If you don't want it to still block, though, you should use BeginInvoke (generally you can do a fire-and-forget and not bother with EndInvoke as you don't need the return value).

In a pure component situation, where you don't have any UI related infrastructure, you should handle the cross thread execution yourself. As I mentioned above, a good way to do this is to have a thread which watches a queue, and have the event handler post a message onto the queue for the handler thread to deal with. You can use WaitHandles (i.e. AutoResetEvent) to notify the thread that it should wake up without doing 'hot waiting' (i.e. checking the queue in a loop).

Alternatively you can spawn new tasks and push them into a ThreadPool or, if using .Net 4, use the Task Parallel classes in the Framework. Both of these mechanisms essentially run a queue and multiple handling threads pulling tasks off them.
GeneralRe: Threading and events Pin
Giorgi Nistor19-Jan-12 22:35
Giorgi Nistor19-Jan-12 22:35 
QuestionMaskedTextBox - Different behavior on different machines, Why? Pin
Michel8318-Jan-12 20:52
Michel8318-Jan-12 20:52 
AnswerRe: MaskedTextBox - Different behavior on different machines, Why? Pin
Eddy Vluggen19-Jan-12 0:27
professionalEddy Vluggen19-Jan-12 0:27 
AnswerRe: MaskedTextBox - Different behavior on different machines, Why? Pin
BobJanova19-Jan-12 0:51
BobJanova19-Jan-12 0:51 
GeneralRe: MaskedTextBox - Different behavior on different machines, Why? Pin
Michel8319-Jan-12 1:24
Michel8319-Jan-12 1:24 
QuestionBest Way To Handle Nulls Pin
Kevin Marois18-Jan-12 11:08
professionalKevin Marois18-Jan-12 11:08 
AnswerRe: Best Way To Handle Nulls Pin
PIEBALDconsult18-Jan-12 11:26
mvePIEBALDconsult18-Jan-12 11:26 
GeneralRe: Best Way To Handle Nulls Pin
fjdiewornncalwe18-Jan-12 11:31
professionalfjdiewornncalwe18-Jan-12 11:31 
GeneralRe: Best Way To Handle Nulls Pin
PIEBALDconsult18-Jan-12 12:21
mvePIEBALDconsult18-Jan-12 12:21 
GeneralRe: Best Way To Handle Nulls Pin
Kevin Marois18-Jan-12 11:53
professionalKevin Marois18-Jan-12 11:53 
GeneralRe: Best Way To Handle Nulls Pin
PIEBALDconsult18-Jan-12 12:17
mvePIEBALDconsult18-Jan-12 12:17 
GeneralRe: Best Way To Handle Nulls Pin
BobJanova18-Jan-12 22:28
BobJanova18-Jan-12 22:28 
GeneralRe: Best Way To Handle Nulls Pin
PIEBALDconsult19-Jan-12 2:20
mvePIEBALDconsult19-Jan-12 2:20 
GeneralRe: Best Way To Handle Nulls Pin
jschell19-Jan-12 8:34
jschell19-Jan-12 8:34 
GeneralRe: Best Way To Handle Nulls Pin
PIEBALDconsult19-Jan-12 13:47
mvePIEBALDconsult19-Jan-12 13:47 
GeneralRe: Best Way To Handle Nulls Pin
BobJanova19-Jan-12 22:14
BobJanova19-Jan-12 22:14 
GeneralRe: Best Way To Handle Nulls Pin
PIEBALDconsult20-Jan-12 2:15
mvePIEBALDconsult20-Jan-12 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.