Do you use Threading to make your user interfaces more responsive?

Last updated by Igor Goldobin about 2 months ago.See history

Threading is not only used to allow a server to process multiple client requests - it could make your user interfaces responsive when your application is performing a long-running process, allowing the user to keep interactive.

:: bad

Figure: Bad example - Unresponsive UI because no threading code
:::

private void Form1_Load(object sender, EventArgs e) 
{ 
    this.ValidateSQLAndCheckVersion();// a long task
} 

Code: No threading code for long task

Figure: Good example - Responsive UI in progress

Figure: Good example - Responsive UI completed

private void Page05StorageMechanism_Load(object sender, EventArgs e)
{
    this.rsSetupOk = false;

    this.databaseSetupOk = false;

    this.NextButtonState.Enabled = false;

    CheckDatabase();

    CheckReports();

}

public void CheckDatabase()
{
    if(sqlConnectionString == null)
    {
       OnValidationFinished(false, false);
    }

    if(upgradeScriptPath ==null && createScriptPath == null)
    {
        OnValidationFinished(false, false);
    }
    
    Thread thread = new Thread(new ThreadStart(this.ValidateSQLAndCheckVersion) ) ;

    thread.Name = "DBCheckingThread";

    thread.Start();
}

Code: Threading code for long task

We open source. Powered by GitHub