ma**************@gmail.com wrote:
[...]
Perhaps it's not too 'good-looking'. In main form I use getIpList()
function, so I thought I'll just refer to it. Perhaps I should repeat
declaration of that function in monitor class? Anyway with dispose it
works just fine.
But that don't answer me, why application hangs when i don't destruct
main form constructor. Any ideas?
I don't know specifically. But note that when the workstation is
locked, there's no desktop for the application to interact with. You
shouldn't be creating a form like that anyway, and it sounds as though
somehow the lack of a desktop causes something to get stuck, maybe
waiting on the processing of a window message that can never happen or
something like that.
Anyway, as I mention above, you shouldn't be creating the form in the
first place. Instantiating a form just because you want to call a
method on the form is very bad. You should only instantiate a form when
you actually want to show a new instance of that form. In all
likelihood you've already got one instance of that form, and that's the
only instance you should ever have.
You didn't post the code for mainForm.getIpList(), but it may not be the
sort of method that really needs to be in the form class in the first
place. The fact that the method works when you call it on a new
instance of the form suggests that there's not actually anything in that
method that uses the data in the form itself.
So, at the very least it seems like you could make the method a static
method, which would allow you to call it without an instance of the
form. It's likely that even better would be to move that method out of
the form class altogether; if it doesn't have anything to do with the
form itself, it's probably better to have it somewhere else (like in
your data management class).
Where to put the method and how to call it are two different issues.
Even if you move it, you'll want to make sure that it's either a static
method, or that you use a pre-existing instance of a class rather than
instantiating a class just so that you can call it.
Pete