Class SchedulerContext
- Namespace
- Quartz
- Assembly
- Quartz.dll
Holds context/environment data that can be made available to Jobs as they are executed.
public sealed class SchedulerContext : IDictionary<string, object?>, ICollection<KeyValuePair<string, object?>>, IReadOnlyDictionary<string, object?>, IReadOnlyCollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IEnumerable
- Inheritance
-
SchedulerContext
- Implements
- Inherited Members
Remarks
The context lives for the whole scheduler: plugins write to it during initialization while jobs and listeners read from it on their own threads, so it is backed by a ConcurrentDictionary<TKey, TValue> and is safe to read and write concurrently. It is never persisted.
The typed read accessors (GetString, TryGetInt and friends) are extension members
declared in DataMapExtensions.
Constructors
SchedulerContext()
Create an empty SchedulerContext.
public SchedulerContext()
SchedulerContext(IDictionary<string, object?>)
Create a SchedulerContext with the given data.
public SchedulerContext(IDictionary<string, object?> map)
Parameters
mapIDictionary<string, object>
Properties
Count
Gets the number of entries contained in the context.
public int Count { get; }
Property Value
IsEmpty
Gets a value indicating whether this instance is empty.
public bool IsEmpty { get; }
Property Value
- bool
trueif this instance is empty; otherwise,false.
this[string]
Gets or sets the object with the specified key.
public object? this[string key] { get; set; }
Parameters
keystring
Property Value
Keys
Gets a snapshot of the keys in the context.
public ICollection<string> Keys { get; }
Property Value
Values
Gets a snapshot of the values in the context.
public ICollection<object?> Values { get; }
Property Value
Methods
Add(string, object?)
Adds an entry with the provided key and value to the context.
public void Add(string key, object? value)
Parameters
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
An entry with the same key already exists in the context.
Clear()
Removes all entries from the context.
public void Clear()
ContainsKey(string)
Determines whether the context contains an entry with the specified key.
public bool ContainsKey(string key)
Parameters
keystringThe key to locate.
Returns
CopyTo(KeyValuePair<string, object?>[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<string, object>[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
arrayIndexis less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndexto the end of the destinationarray.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, object>>
An enumerator that can be used to iterate through the collection.
Remove(string)
Removes the entry with the specified key from the context.
public bool Remove(string key)
Parameters
keystringThe key of the entry to remove.
Returns
TryGetValue(string, out object?)
Gets the value associated with the specified key.
public bool TryGetValue(string key, out object? value)
Parameters
keystringThe key whose value to get.
valueobjectWhen this method returns, contains the value associated with the specified key, if the key is found; otherwise, null.
Returns
- bool
true if the SchedulerContext contains an element with the specified key; otherwise, false.