Events problem

B

Boni

I got a class raising an events.
Another class capture this event and do something. My problem is that until
the second class finish his job I can't dispose the first class. ( releasing
its resources )

How can I separate this processes? possibly without using a thread for the
"something todo"!

thank's
 
P

Patrice

It shouldn't cause a problem. The event is processed immediately (this is
just a method call).

So :
- either you think this is a problem but this is actually something else
(what is the exact problem you see ?)
- or your class is designed in a specific way (it registers the instance and
this instance will be processed at a later time ?) and someone will be
perhaps to suggestr an alternate design

In both cases it's likely we'll need some more details (which kind of
disposable class is this ? how do you know or what is the criterai on whihc
some instance are raisning this event and some other don't ?)
 
J

Jeff Johnson

I got a class raising an events.
Another class capture this event and do something. My problem is that
until
the second class finish his job I can't dispose the first class. (
releasing
its resources )

How can I separate this processes? possibly without using a thread for
the
"something todo"!

In my experience you wouldn't want to do this at all. Events are a "hook."
They let an external class (the subscriber) step into the processing of the
raising class, and the raising class isn't expected to do anything else
until the subscribing class is done "stepping in." Maybe you're trying to
use events for a different purpose, but this is the only purpose I've ever
used them for.
 
F

Family Tree Mike

Boni said:
I got a class raising an events.
Another class capture this event and do something. My problem is that until
the second class finish his job I can't dispose the first class. ( releasing
its resources )

How can I separate this processes? possibly without using a thread for the
"something todo"!

thank's

The only way that I can see for the subscriber to no longer have a hold
of the object during the long running event handler is to unsubscribe
from the event as it happens, then run a background task. Hopefully the
background task does not depend on the sender, else it will keep a
handle to it.

Why did you add the phrase "possbly without using a thread for the
something todo!"? That is the only way I see to do this.
 
P

Peter Duniho

Boni said:
I got a class raising an events.
Another class capture this event and do something. My problem is that until
the second class finish his job I can't dispose the first class. ( releasing
its resources )

Why not?
How can I separate this processes? possibly without using a thread for the
"something todo"!

I'm afraid your question isn't entirely clear. There's a well-known
issue with disposing objects that others may depend on. But in your
description, it's the other way around. You seem to want to dispose an
object that depends on something else (i.e. the second class where the
event handler exists). That's not usually a problem at all.

A concise-but-complete code example that reliably demonstrates the
problem would be helpful.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to Kill an Object? 1
Object garbage collection of events 8
Are multiple events expensive? 3
using events (conceptual) 10
Asnc Calls and events in .net 1.1 2
Thread 7
launching events from a thread 2
Events 2

Top