Andrea,
You must take this as a suggestion of something that might work as I haven’t
had experience in this area and (against good practice) haven’t tried what
I’m suggesting.
You should be able to display any form modally by calling the form’s
ShowDialog() method (Show() would display the same form modelessly) and your
requirement that the lengthy operation takes place on the main thread means
you will know when it finishes simply because it has returned. Therefore, why
not define a simple form with a “Please Wait…” message and an okay button and
do this:
// Set up form
WaitForm form = new WaitForm();
form.okayButton .Enabled = false;
form.Cursor = Cursors.WaitCur sor;
form.ShowDialog ();
// Perform Operation
server.callLeng thyOperation( )
// Allow user to dismiss modal form
form.okayButton .Enabled = true;
form.Cursor = Cursors.Default ;
You might well be able to lose the okay button and dismiss the form simply
by calling form.Close(). And of course, if you use the button, you can just
set Enabled to false in the designer rather than every time you instantiate
the form – I just did it that way to make it explicit. Same goes for the
pointer (or cursor in .net parlance).
You may have some scope problems to deal with in my ‘code’.
You mention threading the new form. Alvin has suggested that you can’t open
windows on a new thread and you say you can’t have your server call on a
different one. It looks like you’re stuck with a code topology at least
similar to mine, but unless you need any user interaction with the modal form
while the server call is progressing, I don’t see why it should matter.
Cheers,
Mike
"an***********@ yahoo.com" wrote:
Hi to everybody,
I have the following situation:
I have a lengthy operation inside a desktop application - something that has
to be executed on the main thread of the app (this is a must)
....
server.callLenn ghtyOperation(. ..)
....
While this operation is executing, I'd like to show a Form (practically a
modal form, that permits no access to the other forms of the application),
just to inform the user about the fact that the operation is being procesed.
Please can you give some ideeas how to do this.
I was thinkin on starting a thread just before the operation, that outputs a
form (well, still got the problem that it has to behave as a modal
window!!!), and after the operation completes signaling the thread that the
it can stop.
I am v much thinking in plain win api terms, being still new to .net.
Thanks in advance,
Andrea