private void ExecuteParallelUpdateGroup() { if (m_ParallelItemsCache.Count == 0) { return; } for (int iBehaviour = 0; iBehaviour < m_ParallelItemsCache.Count; iBehaviour++) { ParallelUpdateItem iterTask = m_ParallelItemsCache[iBehaviour]; BaseBehaviour iterBehaviour = iterTask.Behaviour; try { MDebug.LogVerbose("Core" , $"Before execute {iterBehaviour.GetName()}.OnBeforeParallelUpdate"); iterTask.Input = iterBehaviour.OnBeforeParallelUpdate(iterTask.DeltaTime); MDebug.LogVerbose("Core" , $"After execute {iterBehaviour.GetName()}.OnBeforeParallelUpdate"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {iterBehaviour.GetName()}.OnBeforeParallelUpdate Exception:{e.ToString()}"); } } System.Threading.Tasks.Parallel.For(0, m_ParallelItemsCache.Count, (iBehaviour) => { ParallelUpdateItem iterTask = m_ParallelItemsCache[iBehaviour]; BaseBehaviour iterBehaviour = iterTask.Behaviour; try { MDebug.LogVerbose("Core" , $"Before execute {iterBehaviour.GetName()}.OnParallelUpdate_Thread"); iterTask.Output = iterBehaviour.OnParallelUpdate_Thread(iterTask.Input, iterTask.DeltaTime); MDebug.LogVerbose("Core" , $"After execute {iterBehaviour.GetName()}.OnParallelUpdate_Thread"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {iterBehaviour.GetName()}.OnParallelUpdate_Thread Exception:{e.ToString()}"); } }); for (int iBehaviour = 0; iBehaviour < m_ParallelItemsCache.Count; iBehaviour++) { ParallelUpdateItem iterTask = m_ParallelItemsCache[iBehaviour]; BaseBehaviour iterBehaviour = iterTask.Behaviour; try { MDebug.LogVerbose("Core" , $"Before execute {iterBehaviour.GetName()}.OnAfterParallelUpdate"); iterBehaviour.OnAfterParallelUpdate(iterTask.Output, iterTask.DeltaTime); MDebug.LogVerbose("Core" , $"After execute {iterBehaviour.GetName()}.OnAfterParallelUpdate"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {iterBehaviour.GetName()}.OnAfterParallelUpdate Exception:{e.ToString()}"); } m_ParallelItemPool.Release(iterTask); } m_ParallelItemsCache.Clear(); }