Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Zytan <zytanlithium@xxxxxxxxx>
- Date: 28 May 2007 10:02:05 -0700
You call Invoke() from a static method the same way you'd call from an
instance method, except of course you need to explicitly specify the
instance on which you want to call Invoke(). Obviously this means you
need a reference to the form somewhere......[snip]
Yup, and that's the issue, to have that reference, and to use it when
it could change on you at any moment.
Well, IMHO that's a design problem. I don't think you should design your
code so that that could happen. In particular, it sounds as though you
have threads that can continue to run after your form is closed. But
really, that's a bad idea if you expect those threads to want to
communicate with your form.
Instead, it would be much better to simply have the form not close until
the threads are done. That way, you can be sure that when you go to
Invoke a delegate on the form, the form will still be there.
Pete, the data is coming through a socket connection, and who knows
when the data will arrive. Since the form is just to show the current
stream of data, and is not the main form, I don't want the form to
exist for all time, and be processing all the time (it takes up memory
and CPU resources). I want it to allow it to be opened/closed as
desired. When open, it will show the current data (but also update in
real-time).
Right now, this socket thread checks to see if the form exists, and if
so, invokes a method on it to update itself. There's still that
little chance the form could disappear right AFTER the existance
check, but BEFORE the reference is used to invoke. Things are
properly synch'ed AFTER the invoke, but not before, so that's the
danger area. (I could catch exceptions to prevent a crash, I
suppose).
Zytan
.
- Follow-Ups:
- References:
- Want form to show changing data. But it could be closed, or closing, during update.
- From: Zytan
- Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Zytan
- Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Peter Duniho
- Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Zytan
- Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: Peter Duniho
- Want form to show changing data. But it could be closed, or closing, during update.
- Prev by Date: Re: Want form to show changing data. But it could be closed, or closing, during update.
- Next by Date: Re: Problem with DllImport
- Previous by thread: Re: Want form to show changing data. But it could be closed, or closing, during update.
- Next by thread: Re: Want form to show changing data. But it could be closed, or closing, during update.
- Index(es):
Relevant Pages
|