ILNumerics Ultimate VS

SettingsEnsureT Method (String, T)

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Ensure the value for a specific (static) setting with robust rollback. This should be used in a 'using' directive.

[ILNumerics Core Module]

Namespace:  ILNumerics
Assembly:  ILNumerics.Core (in ILNumerics.Core.dll) Version: (5.5.7503.3146)

public static IDisposable Ensure<T>(
	string Name,
	T Value
where T : struct, new()


Type: SystemString
The name of the setting to modify.
Type: T
The value for the setting.

Type Parameters

Type of the settings value.

Return Value

Type: IDisposable
Disposable object which resets the setting property to its original value when Dispose is called.

This method is useful when a temporary modification to a global setting is needed. It is applied as follows:
  • Enclose the instructions where a certain value for one of the ILNumerics settings is needed into an 'using' block.
  • In the head of the 'using' the EnsureT(String, T) method is called with the name of the setting to control and the new value for it.
  • During the execution of the instructions in the body of the 'using' block the setting Name will have the value provided by Value.
  • Once the body of the 'using' block is left the value of the setting Name will be reset to its original value automatically.

It is advisable to use the C# keyword 'nameof()' in order to provide the name of the setting.

[ILNumerics Core Module]


<code>using (Settings.Ensure(nameof(Settings.MaxNumberThreads), 1)) { //this part runs in single threaded mode // // ... } //here we continue with Settings.MaxNumberThreads set to the original value, before we modified it. </code>
See Also