forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNullSyncInvoker.cs
More file actions
80 lines (71 loc) · 2.79 KB
/
Copy pathNullSyncInvoker.cs
File metadata and controls
80 lines (71 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.ClearScript.Windows.Core
{
/// <summary>
/// Provides a null <c><see cref="ISyncInvoker"/></c> implementation.
/// </summary>
/// <remarks>
/// This class does not enforce thread affinity and should be used with caution. Windows Script
/// engines can behave unpredictably when thread affinity is violated.
/// </remarks>
public class NullSyncInvoker : ISyncInvoker
{
/// <summary>
/// The sole instance of the <c><see cref="NullSyncInvoker"/></c> class.
/// </summary>
public static readonly ISyncInvoker Instance = new NullSyncInvoker();
private NullSyncInvoker()
{
}
#region ISyncInvoker implementation
/// <summary>
/// Determines whether the calling thread has access to the script engine.
/// </summary>
/// <returns><c>True</c> if the calling thread has access to the script engine, <c>false</c> otherwise.</returns>
/// <remarks>
/// The <c><see cref="NullSyncInvoker"/></c> implementation of this method always returns <c>true</c>.
/// </remarks>
public bool CheckAccess()
{
return true;
}
/// <summary>
/// Enforces that the calling thread has access to the script engine.
/// </summary>
/// <remarks>
/// The <c><see cref="NullSyncInvoker"/></c> implementation of this method performs no action.
/// </remarks>
public void VerifyAccess()
{
}
/// <summary>
/// Invokes a delegate that returns no value on the script engine's thread.
/// </summary>
/// <param name="action">The delegate to invoke on the script engine's thread.</param>
/// <remarks>
/// The <c><see cref="NullSyncInvoker"/></c> implementation of this method invokes
/// <paramref name="action"></paramref> without synchronization.
/// </remarks>
public void Invoke(Action action)
{
action();
}
/// <summary>
/// Invokes a delegate that returns a value on the script engine's thread.
/// </summary>
/// <typeparam name="T">The delegate's return value type.</typeparam>
/// <param name="func">The delegate to invoke on the script engine's thread.</param>
/// <returns>The delegate's return value.</returns>
/// <remarks>
/// The <c><see cref="NullSyncInvoker"/></c> implementation of this method invokes
/// <paramref name="func"></paramref> without synchronization.
/// </remarks>
public T Invoke<T>(Func<T> func)
{
return func();
}
#endregion
}
}