Skip to main content
All docs
V22.2

Suppress New Processes Initiated by .NET Controls

  • 3 minutes to read

DevExpress UI controls can initiate new processes in response to user actions. For example, DevExpress RichEdit or HyperlinkEdit controls can open a system’s default browser when a user clicks a hyperlink. When using v19.1 or later, you can use the DevExpress.Data.Utils.ProcessStartPolicy class to apply a policy that manages processes..

Process Start Policies

To apply a policy, call one of the following methods of the DevExpress.Data.Utils.ProcessStartPolicy class at application startup:

  • SuppressAll() - Applies a policy that suppresses all new processes.
  • ThrowAlways() - Applies a policy that throws an exception when a process is about to start.
  • RequireConfirmation() - Applies a policy that displays a confirmation dialog that prompts a user to confirm or cancel a process.

If none of these methods are called, DevExpress controls allow all processes to start. All exceptions that indicate failed processes are suppressed.

The following code suppresses all user-invoked processes:

static void Main() {  
    DevExpress.Data.Utils.ProcessStartPolicy.SuppressAll();  
    //...  
}  

Trusted Resources

The ThrowAlways and RequireConfirmation policies allow you to setup trusted documents, commands, or URLs. Processes for trusted resources bypass exceptions or confirmation dialogs.

To register a trusted resource, use the static RegisterTrustedProcess method:

DevExpress.Data.Utils.ProcessStartPolicy.RegisterTrustedProcess("https://www.devexpress.com");

Process Start Events

To perform custom actions when a DevExpress control starts a process, use the following two events of the ProcessStartPolicy class:

  • Starting - Fires before a process starts and allows you to cancel the process.

    static void Main() {
      ProcessStartPolicy.Starting += ProcessStartPolicy_Starting;
      // ...
    }
    private static void ProcessStartPolicy_Starting(object sender, System.ComponentModel.CancelEventArgs e) {
      ProcessStartInfo psi = sender as ProcessStartInfo;
      e.Cancel = !psi.FileName.Contains("www.devexpress.com");
    }
    
  • Started - Fires after a process has started. This is a notification event.
    static void Main() {
      ProcessStartPolicy.Started += ProcessStartPolicy_Started;
      // ...
    }
    private static void ProcessStartPolicy_Started(object sender, EventArgs e) {
      Process process = sender as Process;
      // ...
      // Log.WriteMessage("process started");
    }
    

Process Start Failures

EExceptions are not raised if a process fails to start. To throw exceptions in this instance, call the static ThrowOnErrors method at application startup.

You can also handle the Failed event to respond to associated failures. The following code handles the Failed event to suppress an internal exception and display a message box.

static void Main() {  
    DevExpress.Data.Utils.ProcessStartPolicy.Failed += ProcessStartPolicy_Failed;  
    //...  
}  

private static void ProcessStartPolicy_Failed(object sender, DevExpress.Data.Utils.ProcessStartPolicy.ProcessStartFailedExceptionEventArgs e) {  
    if(e.Exception is Win32Exception) {  
        System.Diagnostics.ProcessStartInfo si = sender as System.Diagnostics.ProcessStartInfo;  
        e.Throw = false;  
        MessageBox.Show("File not found: " + si.FileName);  
    }  
}