CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2006
    Posts
    97

    [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

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Responsive GUI: design question

    Hi !
    In my applications for very long cycles e.g long dataloading I'm using progressbar. In short cases I'm using text in the statusbar, when ready this again shows 'ready' then. I'm having all the texts for everything in the resources files because there it aslo can be localized if necessary and using only short strings to access this strings like ERR_OPEN, WAIT_LOAD,
    ... Errormessages are posted in MessageBoxes, Wait messages are in the statusbar.

    I dont know if this helps you, but so do I.
    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

  3. #3
    Join Date
    Jul 2006
    Posts
    97

    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

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Responsive GUI: design question

    Have a look at this:

    MSDN Magazine - Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads

    It explains how to update form controls from inside a thread.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Responsive GUI: design question

    Quote 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

  7. #7
    Join Date
    Jul 2006
    Posts
    97

    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

  8. #8
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Responsive GUI: design question

    Quote 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

  9. #9
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    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.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured