public static void Run(Action action)
{
// Only create this object on the main thread
#if NETFX_CORE
if (ReferenceEquals(Instance, null))
#else
if (ReferenceEquals(Instance, null) && Threading.ThreadManagement.IsMainThread)
#endif
{
Create();
}
// If we are in the loop and it is trying to add main thread actions, then add it to the
// back buffer of actions to be added after the loop has been completed
if (inLoop)
{
mainThreadActionsBuffer.Add(action);
return;
}
// Make sure to lock the mutex so that we don't override
// other threads actions
lock (mutex)
{
mainThreadActions.Add(action);
}
}