Modal Workflow
In a program, a modal workflow is a mode of operation in which a particular task or feature must be completed before the user can proceed to other tasks or features. This is typically implemented by displaying a modal window or dialog box that requires user interaction before continuing.
Modal workflows are often used when users must complete specific tasks or provide required information. For example, a modal workflow might prompt users to save work before closing a document, or enter login credentials before accessing restricted areas.
Modal workflows help guide users through specific steps or highlight important actions. However, if overused, they can disrupt workflow.
In web applications, supporting modal workflow means:
Suspending server-side code execution
Waiting for user input
Resuming execution with received user information
While straightforward in desktop applications, this becomes challenging in web applications where code executes on the server and the UI runs asynchronously on different machines.
Modal Workflow
The code and images below demonstrate how Wisej.NET handles modal code execution:
The server code suspends, waiting for user choice. After clicking Yes
or No
on the client-side, the server code resumes exactly where it was suspended.
Wisej.NET supports:
Nested modal states
Custom
DialogResult
valuesControl references in modal dialogs
User input data access
Modal Dialogs
Modal workflow works for MessageBox
and forms (dialog boxes) with any type of control, data binding, and code-behind. The example above, modified to use a modal dialog, looks like this:
Regular modal dialogs or MessageBox
controls suspend the current thread while waiting for user input. By default the system handles about 32,000 threads. While suspended, threads use no CPU time.
Async Modal Dialogs
Wisej.NET fully supports the async/await programming pattern for modal dialogs.
Using the await
keyword, a modal dialog can wait for closure without thread suspension. Simply use the "Async" version of the ShowDialog
method.
The async version of MessageBox
is MessageBox.ShowAsync(...)
.
Asynchronous modal dialogs or MessageBox
controls don't use any threads while waiting for user input.
Custom Modal State
You can implement modal behavior and wait for user input without using modal dialogs or MessageBox
controls. Wisej.NET provides Application.DoModal(component)
for this purpose.
For example, the PropertyGrid
uses Application.DoModal()
to suspend code flow while waiting for dropdown selection box closure. Use Application.EndModal(component, result)
to terminate the last modal state - modal states are stacked.
The code above opens a dropdown and waits for user action. DoModal
returns DialogResult.Cancel
if closed without selection, or DialogResult.OK
otherwise.
This provides powerful control over code execution and user action synchronization.
Application.DoModalAsync(component)
will be added in a future build.
Last updated