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

Updated by Igor Goldobin 1 year ago. See history

123

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

Image

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

Image

✅ Figure: Good example - Responsive UI in progress

Image

✅ 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

acknowledgements
related rules