Partager via


Provide Options During Lengthy Operations

Provide Options During Lengthy Operations

At times, your application must engage in a lengthy networking process. Some strategies are presented here for how to deal with such situations.

Network operations fall into two general categories from the user's point of view:

  • Foreground tasks that block continued interaction until completed
  • Background tasks, during which the user can perform other tasks

For foreground tasks, you need to provide some type of feedback so users understand that they are blocked and cannot continue their work. Ideally, you also offer information about how long the user will be blocked. The type of feedback that is appropriate depends primarily on the duration of the task. If the user can't continue to work with your application until the task is finished, you should provide the option to cancel the operation and include a progress indicator that shows the completion percentage.

For background tasks that don't block the user interface, you don't necessarily have to display notifications when those tasks are finished. You can also silently deal with any connectivity problems that may affect a background task, especially if there's no immediate effect on the user. Subtle status indicators about connection status and the progress of background operations are appreciated but are not always necessary. For user-initiated transfers, a completion notice is necessary only if the user is likely to take some action as a result.

General goals for lengthy operations

For all lengthy operations, you have three goals:

  • Maximize the user's ability to maintain control of the interface and of the mobile PC. It's therefore critical that your application remain usable even if the network connection fails.
  • Allow the user to return as quickly as possible to the main work task.
  • Allow the user to pause the operation. For example, the user might need to leave the scene of the networking connection before the operation has finished.

Here are some guidelines for how to deal with extended-duration network activities:

  • In some cases, a mobile PC might have multiple network connections that can be used to access the resource. If this is the case, test all of them and use the fastest one.
  • Use background threads for lengthy network communication tasks, which allow the user to continue the interaction while the transfer proceeds.
  • Design extended tasks so they can be paused and then resumed from the point of interruption.
  • When you monitor changes in network connectivity (see Handling Network Transitions Transparently), you can respond proactively to connection problems, as well as take advantage of new connections when they become active. A new connection that has just come online might offer better transport performance than the one you started with.
  • If the network activity was not directly requested by the user, consider whether you can defer the transfer until a suitable connection is available.

Provide progress updates for foreground operations

You can estimate the duration of a network task and display appropriate progress feedback for an operation that will not immediately complete. For more information, see Checking Availability Before Attempting Use. If the operation will take a significant amount of time, you can continue to adjust your completion-time estimates as the operation continues.

If possible, perform lengthy network communication tasks in a background thread, which can allow continued interaction with your user interface. If the networking task must occur in the foreground, consider these standard guidelines for any long-running process:

  • For a quick foreground task of two seconds or less, change the cursor to the hourglass until the task is finished. Do not display a dialog box upon completion.
  • For an extended foreground task that requires two minutes or less, show a modal dialog box that includes a determinate progress bar and a cancel button. Do not display a dialog box upon completion. For more information, see Progress Bars.
  • For a task that requires more than two minutes, consider whether you can perform this task in the background. You can use a notification or status indicator to report when the task is finished. For more information, see Notifications and Status Bars.

The following screen shot shows a progress dialog box while a foreground task is in progress.

Dd356072.91b06229-dc7f-4851-8a21-8a4a324d9101(en-us,VS.85).jpg

The following screen shot shows a notification that appears when a background task is completed

Dd356072.ee0a1733-a627-4dae-bae5-7f7a6baf2547(en-us,VS.85).jpg

Implement reasonable time-out periods

If progress can stall during a network operation, allow the user to cancel or postpone the operation until a later time, when the network becomes more responsive. Consider what would be a reasonable time-out period for your application, given the networking conditions that users typically encounter.

If you've set up your application to monitor network status by using the Network Location Awareness Service Provider (NLA), you can respond proactively when a network connection is lost. See Handling Network Transitions Transparently.

Send comments about this topic to Microsoft

Build date: 12/5/2008