31 private const string PROPERTY_NAME =
"Synchronization";
33 private static readonly
int _timeOut = -1;
42 internal Queue _workItemQueue;
45 internal bool _locked;
47 internal bool _bReEntrant;
55 private string _syncLcid;
78 internal string SyncCallOutLCID
90 internal ArrayList AsyncCallOutLCIDList => _asyncLcidList;
92 internal bool IsKnownLCID(
IMessage reqMsg)
95 if (!logicalCallID.Equals(_syncLcid))
97 return _asyncLcidList.
Contains(logicalCallID);
104 : this(4, reEntrant: false)
119 : this(flag, reEntrant: false)
129 : base(
"Synchronization")
131 _bReEntrant = reEntrant;
145 internal void Dispose()
147 if (_waitHandle !=
null)
179 if ((_flavor == 1 && synchronizationAttribute !=
null) || (_flavor == 4 && synchronizationAttribute ==
null))
185 _cliCtxAttr = synchronizationAttribute;
197 if (_flavor != 1 && _flavor != 2 && ctorMsg !=
null)
199 if (_cliCtxAttr !=
null)
211 internal virtual void InitIfNecessary()
215 if (_asyncWorkEvent ==
null)
218 _workItemQueue =
new Queue();
226 private void DispatcherCallBack(
object stateIgnored,
bool ignored)
229 lock (_workItemQueue)
231 work = (WorkItem)_workItemQueue.
Dequeue();
233 ExecuteWorkItem(work);
234 HandleWorkCompletion();
237 internal virtual void HandleThreadExit()
239 HandleWorkCompletion();
242 internal virtual void HandleThreadReEntry()
244 WorkItem workItem =
new WorkItem(
null,
null,
null);
246 HandleWorkRequest(workItem);
249 internal virtual void HandleWorkCompletion()
251 WorkItem workItem =
null;
253 lock (_workItemQueue)
255 if (_workItemQueue.
Count >= 1)
257 workItem = (WorkItem)_workItemQueue.
Peek();
259 workItem.SetSignaled();
268 if (workItem.IsAsync())
270 _asyncWorkEvent.
Set();
282 internal virtual void HandleWorkRequest(WorkItem work)
284 if (!IsNestedCall(work._reqMsg))
289 lock (_workItemQueue)
293 if (!_locked && _workItemQueue.
Count == 1)
297 _asyncWorkEvent.
Set();
306 lock (_workItemQueue)
308 if (!_locked && _workItemQueue.
Count == 0)
325 DispatcherCallBack(
null, ignored:
true);
329 lock (_workItemQueue)
335 else if (!work.IsDummy())
338 ExecuteWorkItem(work);
339 HandleWorkCompletion();
351 internal void ExecuteWorkItem(WorkItem work)
356 internal bool IsNestedCall(
IMessage reqMsg)
361 string syncCallOutLCID = SyncCallOutLCID;
362 if (syncCallOutLCID !=
null)
365 if (logicalCallContext !=
null && syncCallOutLCID.Equals(logicalCallContext.RemotingData.LogicalCallID))
370 if (!flag && AsyncCallOutLCIDList.
Count > 0)
373 if (AsyncCallOutLCIDList.
Contains(logicalCallContext2.RemotingData.LogicalCallID))
389 return new SynchronizedServerContextSink(
this, nextSink);
399 return new SynchronizedClientContextSink(
this, nextSink);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
Represents a handle that has been registered when calling M:System.Threading.ThreadPool....
override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
Adds the Synchronized context property to the specified T:System.Runtime.Remoting....
const int REQUIRED
Indicates that the class to which this attribute is applied must be created in a context that has syn...
Represents the construction call request of an object.
bool Set()
Sets the state of the event to signaled, allowing one or more waiting threads to proceed.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
SynchronizationAttribute(int flag, bool reEntrant)
Initializes a new instance of the T:System.Runtime.Remoting.Contexts.SynchronizationAttribute class w...
Provides a mechanism that synchronizes access to objects.
static bool Wait(object obj, int millisecondsTimeout, bool exitContext)
Releases the lock on an object and blocks the current thread until it reacquires the lock....
SynchronizationAttribute(int flag)
Initializes a new instance of the T:System.Runtime.Remoting.Contexts.SynchronizationAttribute class w...
virtual object Peek()
Returns the object at the beginning of the T:System.Collections.Queue without removing it.
virtual void Enqueue(object obj)
Adds an object to the end of the T:System.Collections.Queue.
Defines an environment for the objects that are resident inside it and for which a policy can be enfo...
virtual IMessageSink GetServerContextSink(IMessageSink nextSink)
Creates a synchronized dispatch sink and chains it in front of the provided chain of sinks at the con...
IDictionary Properties
Gets an T:System.Collections.IDictionary that represents a collection of the message's properties.
const int NOT_SUPPORTED
Indicates that the class to which this attribute is applied cannot be created in a context that has s...
virtual bool IsReEntrant
Gets or sets a Boolean value indicating whether reentry is required.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce)
Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned intege...
virtual bool Contains(object item)
Determines whether an element is in the T:System.Collections.ArrayList.
Contributes an interception sink at the context boundary on the client end of a remoting call.
virtual int Count
Gets the number of elements contained in the T:System.Collections.Queue.
Notifies a waiting thread that an event has occurred. This class cannot be inherited.
SynchronizationAttribute(bool reEntrant)
Initializes a new instance of the T:System.Runtime.Remoting.Contexts.SynchronizationAttribute class w...
delegate void WaitOrTimerCallback(object state, bool timedOut)
Represents a method to be called when a T:System.Threading.WaitHandle is signaled or times out.
virtual IContextProperty GetProperty(string name)
Returns a specific context property, specified by name.
Represents a first-in, first-out collection of objects.
int Add(object value)
Adds an item to the T:System.Collections.IList.
override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
Returns a Boolean value indicating whether the context parameter meets the context attribute's requir...
Indicates that data in the pipe is transmitted and read as a stream of messages.
Provides a set of properties that are carried with the execution code path during remote method calls...
const int REQUIRES_NEW
Indicates that the class to which this attribute is applied must be created in a context with a new i...
SynchronizationAttribute()
Initializes a new instance of the T:System.Runtime.Remoting.Contexts.SynchronizationAttribute class w...
AttributeTargets
Specifies the application elements on which it is valid to apply an attribute.
Contains communication data sent between cooperating message sinks.
const int SUPPORTED
Indicates that the class to which this attribute is applied is not dependent on whether the context h...
The exception that is thrown when one of the arguments provided to a method is not valid.
static void Pulse(object obj)
Notifies a thread in the waiting queue of a change in the locked object's state.
Defines the interface for a message sink.
Specifies that the class can be serialized.
virtual IMessageSink GetClientContextSink(IMessageSink nextSink)
Creates a CallOut sink and chains it in front of the provided chain of sinks at the context boundary ...
Contributes an interception sink at the context boundary on the server end of a remoting call.
SecurityPermissionFlag
Specifies access flags for the security permission object.
virtual bool Locked
Gets or sets a Boolean value indicating whether the T:System.Runtime.Remoting.Contexts....
virtual object Dequeue()
Removes and returns the object at the beginning of the T:System.Collections.Queue.
Provides the default implementations of the T:System.Runtime.Remoting.Contexts.IContextAttribute and ...
Enforces a synchronization domain for the current context and all contexts that share the same instan...
IList ContextProperties
Gets a list of context properties that define the context in which the object is to be created.
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
bool Unregister(WaitHandle waitObject)
Cancels a registered wait operation issued by the M:System.Threading.ThreadPool.RegisterWaitForSingle...
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...