LogoLogo
HomeNewsSupportVideos
  • Introduction
  • Getting Started
  • What's new in 4.0
    • Known Issues
    • .NET Core Designer
    • Managed Graphics
    • Fluent Markup
    • Markdown Support
    • Upgrade from 3.x
  • Releases
    • What's new in 4.0
    • What's new in 3.5
    • What's new in 3.2
      • View Builder
      • Validation Rules
      • Enhanced Font Support
      • Design-Time Debug
    • What's new in 3.1
    • What's new in 3.0
      • FAQs
      • Update Existing Projects
      • Multi Targeting
      • Visual Studio Designer
      • Referencing Assemblies
      • Docker Support
      • Troubleshooting
      • Deployment
    • What's new in 2.5
    • What's new in 2.2
    • What's new in 2.1
    • What's new in 2.0
    • Upgrade from 1.x
  • Getting Started
    • New Project
    • Templates
    • Troubleshooting
    • License Activation
    • FAQ
    • API
    • Hybrid
    • Deployment
    • Theme Builder
  • Concepts
    • Startup
    • Configuration
    • Load Balancing
    • Designer
    • Layouts
    • Client Profiles
    • Tab Order
    • Compression
    • Embedded Resources
    • Modal Workflow
    • Localization
    • RightToLeft
    • Background Tasks
    • Real Time Web Applications
    • JavaScript
    • JavaScript Object Model
    • Security
    • Synchronization
    • Session Management
    • Theming
    • Dependency Injection
    • Application Switches
    • Visual Studio Code
  • Controls & Components
    • General
      • Application
      • AutoSizing
      • AutoScroll
      • AutoScaling
      • Accessibility
      • Colors & Fonts
      • Embedded Tools
      • Events
      • Touch Events
      • Images
      • Labels
      • ToolTips
      • Data Binding
      • Common Properties
      • Custom Painting
      • Move & Resize
      • Drag & Drop
      • Validation
      • User Data
      • Responsive Properties
      • VB.NET Extensions
    • Common Dialogs
      • FolderBrowserDialog
      • ColorDialog
      • OpenFileDialog
      • SaveFileDialog
    • Editors
      • TextBox
        • TagTextBox
        • MaskedTextBox
        • TypedTextBox
      • DateTimePicker
      • MonthCalendar
      • TimeUpDown
      • DomainUpDown
      • NumericUpDown
      • TrackBar
    • Buttons
      • Button
      • SplitButton
      • CheckBox
      • RadioButton
    • Containers
      • Page
      • Form
      • Desktop
      • Panel
      • FlexLayoutPanel
      • FlowLayoutPanel
      • TableLayoutPanel
      • GroupBox
      • Accordion
      • TabControl
      • UserPopup
      • UserControl
      • ToolBar
      • StatusBar
      • SplitContainer
      • SlideBar
    • Lists & Grids
      • ComboBox
        • UserComboBox
        • TreeViewComboBox
        • ListViewComboBox
      • ListBox
        • CheckedListBox
      • TreeView
      • ListView
      • DataGridView
        • Column
        • TextBoxColumn
        • ButtonColumn
        • LinkColumn
        • ImageColumn
        • MaskedTextBoxColumn
        • DateTimePickerColumn
        • NumericUpDownColumn
        • CheckBoxColumn
        • ComboBoxColumn
      • DataRepeater
      • PropertyGrid
    • Extenders
      • Animation
      • ToolTip
      • ErrorProvider
      • Rotation
      • StyleSheet
      • JavaScript
    • Media
      • Audio
      • Video
      • FlashPlayer
    • Content
      • Label
      • LinkLabel
      • PictureBox
      • ScrollBars
      • Upload
      • AspNetPanel
      • ImageList
      • PdfViewer
      • ProgressBar
      • Spacer
      • Widget
      • WebBrowser
      • IFramePanel
      • HtmlPanel
      • Canvas
      • Shape
      • Line
    • Menus
      • MainMenu
      • MenuBar
      • MenuItem
      • LinkMenuItem
      • ContextMenu
    • Notifications
      • AlertBox
      • MessageBox
      • Toast
    • Other Components
      • Timer
      • BindingSource
      • BindingNavigator
      • DataSet
      • EventLog
      • MessageQueue
      • PerformanceCounter
Powered by GitBook
On this page
  • Modal Workflow
  • Modal Dialogs
  • Async Modal Dialogs
  • Custom Modal State

Was this helpful?

Export as PDF
  1. Concepts

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:

void button1_Click(object sender, EventArgs e)
{
    if (MessageBox.Show("Are you sure?", buttons: MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
          this.button1.BackColor = Color.Green;
          this.button1.Text = "You selected: Yes!";
    }
}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
	If MessageBox.Show("Are you sure?", buttons:=MessageBoxButtons.YesNo) = DialogResult.Yes Then
		Me.Button1.BackColor = Color.Green
		Me.Button1.Text = "You selected: Yes!"
	End If
End Sub

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 values

  • Control 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:

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);
    }
  }
}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
	Using dialog As New EnterCustomerAddress()
		If dialog.ShowDialog(Me) = DialogResult.OK Then
			AlertBox.Show(dialog.textBoxAddress.Text + " " + dialog.textBoxState.Text)
		End If
	End Using
End Sub

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(...).

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);
    }
  }
}
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
	Using dialog As New EnterCustomerAddress()
		If Await dialog.ShowDialogAsync(Me) = DialogResult.OK Then
			AlertBox.Show(dialog.textBoxAddress.Text + " " + dialog.textBoxState.Text)
		End If
	End Using
End Sub

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.

// Open the combo box drop down list and wait
// for the user to select an item or close the combo box.
private void button1_Click(object sender, EventArgs e)
{
	this.comboBox1.DroppedDown = true;
	this.comboBox1.DropDownClosed += ComboBox1_DropDownClosed;
	this.comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;

	// wait for the user to either pick an item or close the drop down.
	var result = Application.DoModal(this.comboBox1);

	// code execution will resume here.
}

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
	this.comboBox1.DropDownClosed -= ComboBox1_DropDownClosed;
	Application.EndModal(this.comboBox1, DialogResult.OK);
}

private void ComboBox1_DropDownClosed(object sender, EventArgs e)
{
	Application.EndModal(this.comboBox1, DialogResult.Cancel);
}
' Open the combo box drop down list and wait
' for the user to select an item or close the combo box.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

	Me.ComboBox1.DroppedDown = True
	AddHandler Me.ComboBox1.DropDownClosed, AddressOf ComboBox1_DropDownClosed
	AddHandler Me.ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged

	' wait for the user to either pick an item or close the drop down.
	Dim result As DialogResult = Application.DoModal(Me.ComboBox1)

	' code execution will resume here.

End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)

	RemoveHandler Me.ComboBox1.DropDownClosed, AddressOf ComboBox1_DropDownClosed
	Application.EndModal(Me.ComboBox1, DialogResult.OK)

End Sub

Private Sub ComboBox1_DropDownClosed(sender As Object, e As EventArgs)

	Application.EndModal(Me.ComboBox1, DialogResult.Cancel)

End Sub

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.

PreviousEmbedded ResourcesNextLocalization

Last updated 3 months ago

Was this helpful?

Before clicking the button.
After clicking the button.
After the user selected Yes.