Skip to main content
All docs
V24.2

EnvironmentPolicy Class

Allows you to spot, analyze, and prohibit unwanted requests to System.Environment initiated by DevExpress controls.

Namespace: DevExpress.Data.Utils

Assembly: DevExpress.Data.v24.2.dll

Declaration

public static class EnvironmentPolicy

Remarks

DevExpress UI controls can access (read and write) information about the environment in which an application is running. The EnvironmentPolicy allows you to apply global environment access restrictions, or track app initiated requests and execute custom actions in response.

Use the following methods at application startup to apply a restrictive policy:

The following example suppresses all requests to System.Environment initiated by DevExpress controls:

using System;
using System.Windows.Forms;

namespace EnvironmentPolicyDemo {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.Data.Utils.EnvironmentPolicy.SuppressAll();
            Application.Run(new Form1());
        }
    }
}

Use the following methods to trace and handle exceptions:

  • ThrowAlways() – Throws an exception when the DevExpress control accesses System.Environment.
  • ThrowOnErrors() – Throws an exception if a request to System.Environment fails.

Handle the Failed event to respond to associated failures.

using System;
using System.Windows.Forms;

namespace EnvironmentPolicyDemo {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.Data.Utils.EnvironmentPolicy.ThrowOnErrors();
            DevExpress.Data.Utils.EnvironmentPolicy.Failed += EnvironmentPolicy_Failed;
            Application.Run(new Form1());
        }

        static void EnvironmentPolicy_Failed(object sender, DevExpress.Data.Utils.EnvironmentPolicy.FailedEventArgs e) {
            Console.WriteLine(e.Exception.Message);
            e.Throw = false;
        }
    }
}

Handle the following events to allow or cancel environment-related operations based on a specific condition:

Tip

Read the following topic for additional information: Environment Policy.

Inheritance

Object
EnvironmentPolicy
See Also