Skip to content

Instantly share code, notes, and snippets.

@Mouledoux
Created September 16, 2020 14:54
Show Gist options
  • Save Mouledoux/7331c8b71aafaa4701c04eb5c12a6b6b to your computer and use it in GitHub Desktop.
Save Mouledoux/7331c8b71aafaa4701c04eb5c12a6b6b to your computer and use it in GitHub Desktop.
private static void RemoveCorruptSubscriptions(string a_message)
{
if (m_subscriptions.TryGetValue(a_message, out List<Subscription> tSub))
{
for (int i = 0; i < tSub.Count; i++)
{
try
{
foreach (Action<T> del in tSub[i].Callback.GetInvocationList())
{
tSub[i].Callback -= del.Target.Equals(null) ? del : default;
}
if (tSub[i].Callback == null)
{
m_subscriptions[a_message].RemoveAt(i);
i--;
}
else
{
m_subscriptions[a_message][i] = tSub[i];
}
}
catch (NullReferenceException)
{
tSub.RemoveAt(i);
i--;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment