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

Loading last updated info...

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.

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

Authors

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star