Class ContentManagerAsyncExtensions
Async Load/Reload helpers for ContentManager that propagate the calling MicroThread's synchronization context onto the task — required for code paths that rely on MicroThreadLocal values (e.g. selecting the active database).
public static class ContentManagerAsyncExtensions
- Inheritance
-
objectContentManagerAsyncExtensions
Methods
LoadAsync(ContentManager, Type, string, ContentManagerLoaderSettings?)
Loads an asset from the specified URL asynchronously.
public static Task<object> LoadAsync(this ContentManager contentManager, Type type, string url, ContentManagerLoaderSettings? settings = null)
Parameters
contentManagerContentManagerThe content manager.
typeTypeThe type.
urlstringThe URL.
settingsContentManagerLoaderSettingsThe settings.
Returns
- Task<object>
The loaded content.
Remarks
If the asset is already loaded, it just increases the reference count of the asset and return the same instance.
LoadAsync<T>(IContentManager, UrlReference<T>, ContentManagerLoaderSettings?)
Loads content from the specified UrlReference<T> asynchronously.
public static Task<T> LoadAsync<T>(this IContentManager content, UrlReference<T> urlReference, ContentManagerLoaderSettings? settings = null) where T : class
Parameters
contentIContentManagerThe IContentManager.
urlReferenceUrlReference<T>The URL to load from.
settingsContentManagerLoaderSettingsThe settings. If null, fallback to Default.
Returns
- Task<T>
The loaded content.
Type Parameters
TThe content type.
Exceptions
- ArgumentNullException
If
urlReferenceisnullorempty. Orcontentisnull.
LoadAsync<T>(IContentManager, string, ContentManagerLoaderSettings?)
Loads an asset from the specified URL asynchronously.
public static Task<T> LoadAsync<T>(this IContentManager contentManager, string url, ContentManagerLoaderSettings? settings = null) where T : class
Parameters
contentManagerIContentManagerThe content manager.
urlstringThe URL to load from.
settingsContentManagerLoaderSettingsThe settings. If null, fallback to Default.
Returns
- Task<T>
The loaded content.
Type Parameters
TThe content type.
Remarks
If the asset is already loaded, it just increases the reference count of the asset and return the same instance.
ReloadAsync(ContentManager, object, string?, ContentManagerLoaderSettings?)
Reloads a previously loaded asset asynchronously.
public static Task<bool> ReloadAsync(this ContentManager contentManager, object obj, string? newUrl = null, ContentManagerLoaderSettings? settings = null)
Parameters
contentManagerContentManagerThe content manager.
objobjectThe object to reload.
newUrlstringThe url of the new object to load. This allows to replace an asset by another one, or to handle renamed content.
settingsContentManagerLoaderSettingsThe loader settings.
Returns
- Task<bool>
A task that completes when the content has been reloaded. The result of the task is True if it could be reloaded, false otherwise.
Exceptions
- InvalidOperationException
Content not loaded through this ContentManager.