|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
threaded modal windowI 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 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. -- Show quoteWarm 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 ------------------------------------------------------- <anastasesc***@yahoo.com> wrote in message news:eWToaLiQGHA.1728@TK2MSFTNGP11.phx.gbl... > 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 > > well, but how to make the threaded window look "modal"?
Show quote "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message news:OzGpZfiQGHA.5280@TK2MSFTNGP12.phx.gbl... >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. > > -- > 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 > ------------------------------------------------------- > > > > <anastasesc***@yahoo.com> wrote in message > news:eWToaLiQGHA.1728@TK2MSFTNGP11.phx.gbl... >> 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 >> >> > > 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 Show quote "anastasesc***@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.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 > > > |
|||||||||||||||||||||||