Class JoinableTaskContextNode
- Namespace
- Microsoft.VisualStudio.Threading
- Assembly
- Microsoft.VisualStudio.Threading.dll
A customizable source of JoinableTaskFactory instances.
public class JoinableTaskContextNode
- Inheritance
-
JoinableTaskContextNode
- Inherited Members
Constructors
JoinableTaskContextNode(JoinableTaskContext)
Initializes a new instance of the JoinableTaskContextNode class.
public JoinableTaskContextNode(JoinableTaskContext context)
Parameters
context
JoinableTaskContextThe inner JoinableTaskContext.
Properties
Context
Gets the inner wrapped context.
public JoinableTaskContext Context { get; }
Property Value
Factory
Gets the factory which creates joinable tasks that do not belong to a joinable task collection.
public JoinableTaskFactory Factory { get; }
Property Value
IsOnMainThread
Gets a value indicating whether the caller is executing on the main thread.
public bool IsOnMainThread { get; }
Property Value
MainThread
Gets the main thread that can be shared by tasks created by this context.
public Thread MainThread { get; }
Property Value
Methods
CreateCollection()
Creates a collection for in-flight joinable tasks.
public JoinableTaskCollection CreateCollection()
Returns
- JoinableTaskCollection
A new joinable task collection.
CreateDefaultFactory()
Creates a factory without a JoinableTaskCollection.
protected virtual JoinableTaskFactory CreateDefaultFactory()
Returns
Remarks
Used for initializing the Factory property.
CreateFactory(JoinableTaskCollection)
Creates a joinable task factory that automatically adds all created tasks to a collection that can be jointly joined.
public virtual JoinableTaskFactory CreateFactory(JoinableTaskCollection collection)
Parameters
collection
JoinableTaskCollectionThe collection that all tasks should be added to.
Returns
IsMainThreadBlocked()
Gets a value indicating whether the main thread is blocked for the caller's completion.
public bool IsMainThreadBlocked()
Returns
OnFalseHangDetected(TimeSpan, Guid)
Invoked when an earlier hang report is false alarm.
protected virtual void OnFalseHangDetected(TimeSpan hangDuration, Guid hangId)
Parameters
hangDuration
TimeSpanThe duration of the total waiting time.
hangId
GuidA GUID that uniquely identifies the earlier hang report.
OnHangDetected(HangDetails)
Invoked when a hang is suspected to have occurred involving the main thread.
protected virtual void OnHangDetected(JoinableTaskContext.HangDetails details)
Parameters
details
JoinableTaskContext.HangDetailsDescribes the hang in detail.
Remarks
A single hang occurrence may invoke this method multiple times, with increasing
values in the NotificationCount values
in the details
parameter.
OnHangDetected(TimeSpan, int, Guid)
Invoked when a hang is suspected to have occurred involving the main thread.
protected virtual void OnHangDetected(TimeSpan hangDuration, int notificationCount, Guid hangId)
Parameters
hangDuration
TimeSpanThe duration of the current hang.
notificationCount
intThe number of times this hang has been reported, including this one.
hangId
GuidA random GUID that uniquely identifies this particular hang.
Remarks
A single hang occurrence may invoke this method multiple times, with increasing
values in the hangDuration
parameter.
RegisterOnHangDetected()
Registers with the inner JoinableTaskContext to receive hang notifications.
protected IDisposable RegisterOnHangDetected()
Returns
- IDisposable
A value to dispose of to cancel hang notifications.
SuppressRelevance()
Conceals any JoinableTask the caller is associated with until the returned value is disposed.
public JoinableTaskContext.RevertRelevance SuppressRelevance()
Returns
- JoinableTaskContext.RevertRelevance
A value to dispose of to restore visibility into the caller's associated JoinableTask, if any.
Remarks
In some cases asynchronous work may be spun off inside a delegate supplied to Run,
so that the work does not have privileges to re-enter the Main thread until the
Run(Func<Task>) call has returned and the UI thread is idle.
To prevent the asynchronous work from automatically being allowed to re-enter the Main thread,
wrap the code that calls the asynchronous task in a using
block with a call to this method
as the expression.
this.JoinableTaskContext.RunSynchronously(async delegate {
using(this.JoinableTaskContext.SuppressRelevance()) {
var asyncOperation = Task.Run(async delegate {
// Some background work.
await this.JoinableTaskContext.SwitchToMainThreadAsync();
// Some Main thread work, that cannot begin until the outer RunSynchronously call has returned.
});
}
// Because the asyncOperation is not related to this Main thread work (it was suppressed),
// the following await *would* deadlock if it were uncommented.
////await asyncOperation;
});