corelibraries-devexpress-dot-data-dot-utils-549369c0.md
Allows you to spot, analyze, and prohibit unwanted requests to System.Environment initiated by DevExpress controls.
Namespace : DevExpress.Data.Utils
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
public static class EnvironmentPolicy
Public Module EnvironmentPolicy
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:
System.Environment. No exception is thrown.CurrentDirectory, ProcessId, ProcessPath).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());
}
}
}
Imports System
Imports System.Windows.Forms
Namespace EnvironmentPolicyDemo
Friend Module Program
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread>
Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
DevExpress.Data.Utils.EnvironmentPolicy.SuppressAll()
Application.Run(New Form1())
End Sub
End Module
End Namespace
Use the following methods to trace and handle exceptions:
System.Environment.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;
}
}
}
Imports System
Imports System.Windows.Forms
Namespace EnvironmentPolicyDemo
Friend Module Program
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread>
Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
DevExpress.Data.Utils.EnvironmentPolicy.ThrowOnErrors()
AddHandler DevExpress.Data.Utils.EnvironmentPolicy.Failed, AddressOf EnvironmentPolicy_Failed
Application.Run(New Form1())
End Sub
Private Sub EnvironmentPolicy_Failed(ByVal sender As Object, ByVal e As DevExpress.Data.Utils.EnvironmentPolicy.FailedEventArgs)
Console.WriteLine(e.Exception.Message)
e.Throw = False
End Sub
End Module
End Namespace
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.
Object EnvironmentPolicy
See Also