|
-
September 29th, 2007, 09:56 AM
#1
[RESOLVED] Responsive GUI: design question
Hello all!
I'm trying to make my program more user friendly and the first thing that came into my mind was making the GUI fully responsive. I have a lot of methods that involve looping and other time consuming tasks. I created a window to show a message to user, like "Doing some task, please wait...". The window then calls a method on a separate thread, to stay responsive. Now the question is:
I have some methods that I would like to report their progress. Like, for example, an auto-update method - I would like it to be able to show messages like "Checking for updates" then change to "Updating..." and finally "Update successful!".
I do already have a method SetText() implemented for the information window, but I can't think of the best way to use it. I want the methods I call in another thread to NOT contain any GUI related code, so I don't want to pass the information window object to the methods. Note, I do know about invoking and I already solved all GUI and MT related problems 
Please share your thoughts about this issue, maybe there's some effective way you're all using?
I appreciate, as always, any comments of the gurus
Last edited by gecka; September 30th, 2007 at 07:36 AM.
Using .NET 2.0 
-
September 29th, 2007, 03:08 PM
#2
-
September 30th, 2007, 01:07 AM
#3
Re: Responsive GUI: design question
Thanks, JonnyPoet, for input, but this doesn't solve my problem... 
My problem is how to have the lengthy methods report their progress without using any calls to GUI from the code. The biggest problem is that I need the progress to be reported several times, not only one, so I can't just set the waiting message in GUI level. I was thinking about a delegate as one of the arguments to all these methods, something like:
Code:
public delegate void ProgressCallback(string text);
From the GUI code I would pass the SetText(string text) method as the argument then.
Is this a good enough way to do this?..
Thanks.
Using .NET 2.0 
-
September 30th, 2007, 03:20 AM
#4
Re: Responsive GUI: design question
Check out the 'Model View Presenter' and 'Model View Controller' design patterns.
I found the 'Design Patterns Bootcamp: Model View * Patterns' to be helpful.
Check out the videos in the article as well as the MVP code stub generator.
The idea here is that an interface is used to connect the view to a presenter. The interface can contain events, methods, properties etc (eh, the usual stuff). In your case, your form class would be derived from Form and this interface and you would connect up the interface items with the form controls.
The presenter class typically call other class(es) that implement the multithreading or other service operations.
-
September 30th, 2007, 04:46 AM
#5
Re: Responsive GUI: design question
-
September 30th, 2007, 05:03 AM
#6
Re: Responsive GUI: design question
 Originally Posted by gecka
....My problem is how to have the lengthy methods report their progress without using any calls to GUI from the code. The biggest problem is that I need the progress to be reported several times, not only one,....
Yes but isn't this just the same way as if you are feeding a progressbar with information that the progressincreases and it has to show a new state of progress now. During loading I do this several times and in different amounts using a callback delegate from the GUI. The GUI would report in any way I want, so I also could show different messages instead of using a progressbar. (I'm working with a backgroundworker this way.) So in the moment I cannot see the problem ? Is it how to transport data or hw to build the calllback ?
Last edited by JonnyPoet; September 30th, 2007 at 09:42 AM.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
September 30th, 2007, 05:51 AM
#7
Re: Responsive GUI: design question
Hmm, I'll probably go with delegates in this program then, like JonnyPoet said.
But the link Arjay gave is very useful too, thanks for it.
As the program is getting bigger and bigger, I'm starting to feel the need of clear design from the beginning of the project... Gonna have to rewrite some code now. :\
Thanks for all replies.
Using .NET 2.0 
-
September 30th, 2007, 07:04 AM
#8
Re: Responsive GUI: design question
 Originally Posted by gecka
...As the program is getting bigger and bigger, I'm starting to feel the need of clear design from the beginning of the project...
I think everybody of us, who ever did bigger projects, knows that feeling I'm just on rerwriting an old Access.mdb VBA application to an C# MS-SQLServer - Client Application and I'm in the design matter since one year now, doing some small testings and the most work is only going into how to design the new database for a better and easier handling of the given needs in some very complex data relations.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
September 30th, 2007, 09:34 AM
#9
Re: Responsive GUI: design question
Just use a BackgroundWorker component. You call its RunWorkerAsync method and you do the work in its DoWork event handler. You call its ReportProgress method and update the UI in its ProgressChanged event handler. The whole point of the BackgroundWorker is to simplify multi-threading by removing the need for you to worry about what thread you're on. You don't have to create a background thread and you don't have to use any delegation to access the UI. All that happens but it happens behind the BackgroundWorker so you don't have to worry about the details. It's not suitable for all multi-threading scenarios but for most it will make your life easier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|