Re: Want form to show changing data. But it could be closed, or closing, during update.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: Urgent : InvalidCast... Please help me..
    ... "Bsiang Tan" wrote in message ... > invoke the same static method as before. ... > using Reflection caot work? ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Calling a static method by name
    ... following function signature: ... as appropriate) and then invoke the member function. ... just package up your individual parameters in the object array. ... > would need to call a static method of a class which has the same name. ...
    (microsoft.public.dotnet.languages.csharp)
  • Urgent : InvalidCast.. Please help me
    ... An assembly which is a WebService proxcy client ... invoke the same static method as before. ... using Reflection caot work? ...
    (microsoft.public.dotnet.languages.csharp)
  • Urgent : InvalidCast... Please help me..
    ... An assembly which is a WebService proxcy client ... invoke the same static method as before. ... using Reflection caot work? ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Urgent : InvalidCast.. Please help me ~
    ... An assembly which is a WebService proxcy client ... invoke the same static method as before. ... using Reflection caot work? ...
    (microsoft.public.dotnet.framework.aspnet.webservices)