Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

threaded modal window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
anastasescu_a@yahoo.com - 07 Mar 2006 20:08 GMT
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.callLennghtyOperation(...)
...

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
Alvin Bruney - ASP.NET MVP - 07 Mar 2006 20:43 GMT
a threaded modal window is a bit of a misnomer, there really is no such
animal. windows belong to the main thread. What you can do is fire a window
form and have your main thread pole the child thread to see if it is
finished. When it is, you can take down the window.

Signature

Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

> Hi to everybody,
>
[quoted text clipped - 19 lines]
> Thanks in advance,
> Andrea
anastasescu_a@yahoo.com - 07 Mar 2006 21:02 GMT
well, but how to make the threaded window look "modal"?
>a threaded modal window is a bit of a misnomer, there really is no such
> animal. windows belong to the main thread. What you can do is fire a
[quoted text clipped - 31 lines]
>> Thanks in advance,
>> Andrea
Mike - 09 Mar 2006 17:02 GMT
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.WaitCursor;
form.ShowDialog();

// Perform Operation
server.callLengthyOperation(…)

// 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

> Hi to everybody,
>
[quoted text clipped - 19 lines]
> Thanks in advance,
> Andrea

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.