Re: Want form to show changing data. But it could be closed, or closing, during update.
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Sat, 26 May 2007 16:33:38 -0700
On Sat, 26 May 2007 12:48:19 -0700, Zytan <zytanlithium@xxxxxxxxx> wrote:
[...]
Ok, but, even without Join(), and using Invoke(), how can I make a
static method in the form invoke a method on the form itself (so it
can update the GUI in it)? Even if things are syncrhonized, how do I
get to that point of them being synchronized?
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, but you're not going to get anywhere without that, so I will take that for granted.
Note that if you were using an event to deal with this communication issue, the delegate handler added to the event from the form would include the reference to the form itself. I'm not really clear on why you're using a static method, but even using a static method, going through an event provides a clean way to include the reference to the form.
Another thread is updating the data, and a function in this thread
wants to tell the form to update its GUI to show the data. How can it
be synchronized to know if the form exists, and if so, invoke on that
form? The form may close between the check, and the call.
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
.
- 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
- 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: ... -- Coming Very Soon
- 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
|