Game Development Reference
ResultLabel.Text = “Cancelled”;
ResultLabel.Text = e.Result.ToString();
ComputeNumberField.Enabled = true;
ComputeButton.Enabled = true;
CancellationButton.Enabled = false;
Creating a user interface that is responsive is not that difficult, provided that you
know the techniques required to do so. Your code must divide time between pro-
cessing a long-running task and interacting with the user; one should not be sacrificed
for the other. You cannot think in a linear fashion when building a long-running
task; your application cannot wait around for the task to complete. Think about
a good place in the processing logic to stop and report status back to the user.
Thankfully, you do not have to worry about processing application events while
using the BackgroundWorker object, because this is done behind the scenes for you.
Figure 37.1 shows a screenshot of the demo application provided on the Companion
Screenshot of the demo application on the Web site.
Asynchronous processing can drastically improve the responsiveness of your
application. However, do not assume that an asynchronous model is always the
best approach; sometimes a synchronous model is a better choice. Thankfully, .NET
2.0 simplifies the tasks related to using either execution model.