Click or drag to resize

Modal Workflow

By "Modal workflow" we mean the ability to suspend the execution of server side code, waiting for user input, and to be able to resume the execution flow using any information that may have been receive from the user.

It's simple when running a desktop application. It's very hard when running a web application where the code is being executed on the server and the UI is completely asynchronous and running on different machines.

Modal Workflow in Wisej

The code and images below illustrate how Wisej handles modal execution of code:

C#
void button1_Click(object sender, EventArgs e)
{
    if (MessageBox.Show("Are you sure?", buttons: MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
          this.button.BackColor = Color.Green;
          this.button1.Text = "You selected: Yes!";
    }
}
Before clicking the button
modal-1
After clicking the button
modal-2

Now the server code is suspended, waiting for the user to choose. After the user clicks Yes or No, on the client side, the server code will resume exactly where it was suspended:

After the user selected Yes.
modal-3

Wisej can handle nested modal states, custom dialog results and can reference controls in the modal dialog, as well as any data entered by the user .

Modal Dialogs

Modal workflow works for message boxes 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:

C#
void button1_Click(object sender, EventArgs e)
{
  using (new dialog = new EnterCustomerAddress())
  {
    if (dialog.ShowDialog(this) == DialogResult.OK)
    {
        AlertBox.Show(dialog.textBoxAddress.Text + " " + dialog.textBoxState.Text);
    }
  }
}
Async Modal Dialogs

Wisej fully supports the async/await programming pattern also for modal dialogs.

Using the await keyword a modal dialog can wait to be closed without suspending the thread. Just use the "Async" version of the ShowDialog method.

Tip Tip

The async version of the MessageBox is MessageBox.ShowAsync(...).

C#
void async button1_Click(object sender, EventArgs e)
{
  using (new dialog = new EnterCustomerAddress())
  {
    if (await dialog.ShowDialogAsync(this) == DialogResult.OK)
    {
        AlertBox.Show(dialog.textBoxAddress.Text + " " + dialog.textBoxState.Text);
    }
  }
}
See Also