WeakEventManager.ListenerList.PrepareForWriting Method (WeakEventManager.ListenerList)


Checks to see whether the provided list is in use, and if so, sets the list reference parameter to a copy of that list rather than the original.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

public static bool PrepareForWriting(
	ref WeakEventManager.ListenerList list


Type: System.Windows.WeakEventManager.ListenerList

The list to check for use state and potentially copy.

Return Value

Type: System.Boolean

true if the provided list was in use at the time of call and therefore the list parameter reference was reset to be a copy. false if the provided list was not in use, in which case the list parameter reference remains unaltered.

If the given list is in use (which means an event is currently being delivered), calling this method will replace the input list with a clone. The existing users will finish delivering the event to the original list, without interference from changes to the new list.

If the method returns true, callers may want to insert the new list in their own data structures, since this indicates the possibility that the provided list is no longer current.

This method calls BeginUse internally and then immediately calls EndUse. Therefore calling PrepareForWriting does not itself introduce a lock on the list. Even the clone copy is done as a secondary operation after calling EndUse.

.NET Framework
Available since 3.0
Return to top