Best practice for controlling a busy GUI

Posted by MPelletier on Stack Overflow See other posts from Stack Overflow or by MPelletier
Published on 2010-03-27T21:46:34Z Indexed on 2010/03/27 21:53 UTC
Read the original article Hit count: 459

Suppose a GUI (C#, WinForms) that performs work and is busy for several seconds. It will still have buttons that need to remain accessible, labels that will change, progress bars, etc.

I'm using this approach currently to change the GUI when busy:

//Generic delegates
private delegate void SetControlValue<T>(T newValue);

//...
public void SetStatusLabelMessage(string message)
{
    if (StatusLabel.InvokeRequired)
        StatusLabel.BeginInvoke(new SetControlValue<string>(SetStatusLabelMessage, object[] { message });
    else
        StatusLabel.Text = message;
}

I've been using this like it's going out of style, yet I'm not quite certain this is proper. Creating the delegate (and reusing it) makes the whole thing cleaner (for me, at least), but I must know that I'm not creating a monster...

© Stack Overflow or respective owner

Related posts about c#

Related posts about delegates