J
JohnM
Hi there,
Are there any specific rules or best-practices I should be aware regarding
events and the threads they're fired on. Object 1 can be created on thread 1
for instance and an event then registered with it on thread 2. Object 1
might then fire the event on thread 3 and the event might later be
deregistered on thread 4. Are there any inherent problems with these (and
other) scenarios so long as the event handler is properly dealing with its
own synchronization issues. Note that I'm asking because I recently received
the exception:
"COM object that has been separated from its underlying RCW cannot be used"
This apparently occurred because I was registering and deregestering my
handler for a (native Visual Studio) event on thread 2 even though the
object firing the event was created on thread 1 (and firing on thread 1). It
even causes VS itself to consistently crash but I could later see that it
had something to do with some underlying calls to "Advise()" and
"Unadvise()" (for those familiar with COM). Apparently I must be breaking
the thread affinity rules since the problem disappears if I register and
unregister my handler on thread 1 instead. Any insight would be appreciated.
Thanks.
Are there any specific rules or best-practices I should be aware regarding
events and the threads they're fired on. Object 1 can be created on thread 1
for instance and an event then registered with it on thread 2. Object 1
might then fire the event on thread 3 and the event might later be
deregistered on thread 4. Are there any inherent problems with these (and
other) scenarios so long as the event handler is properly dealing with its
own synchronization issues. Note that I'm asking because I recently received
the exception:
"COM object that has been separated from its underlying RCW cannot be used"
This apparently occurred because I was registering and deregestering my
handler for a (native Visual Studio) event on thread 2 even though the
object firing the event was created on thread 1 (and firing on thread 1). It
even causes VS itself to consistently crash but I could later see that it
had something to do with some underlying calls to "Advise()" and
"Unadvise()" (for those familiar with COM). Apparently I must be breaking
the thread affinity rules since the problem disappears if I register and
unregister my handler on thread 1 instead. Any insight would be appreciated.
Thanks.