/// <summary> /// Enqueues an operation to remove the root view. /// </summary> /// <param name="rootViewTag">The root view tag.</param> public void EnqueueRemoveRootView(int rootViewTag) { // Called on layout manager thread UIViewOperationQueueInstance queue = GetQueueByTag(rootViewTag); // Send forward queue.EnqueueRemoveRootView(rootViewTag); // Do some maintenance/cleanup if needed. // Find the queue info var pair = _dispatcherToOperationQueueInfo.First(p => p.Value.queueInstance == queue); // Decrement number of root views pair.Value.rootViewCount--; if (queue != MainUIViewOperationQueue) { if (pair.Value.rootViewCount == 0) { // We can remove this queue and then destroy _dispatcherToOperationQueueInfo.Remove(pair.Key); // Simulate an OnDestroy from the correct dispatcher thread // (OnResume/OnSuspend/OnDestroy have this thread affinity, all other methods do enqueuings in a thread safe manner) DispatcherHelpers.RunOnDispatcher(pair.Key, queue.OnDestroy); } } }
/// <summary> /// Enqueues an operation to remove the root view. /// </summary> /// <param name="rootViewTag">The root view tag.</param> public Task RemoveRootViewAsync(int rootViewTag) { // Called on layout manager thread UIViewOperationQueueInstance queue = GetQueueByTag(rootViewTag); // Send forward queue.EnqueueRemoveRootView(rootViewTag); // Do some maintenance/cleanup if needed. // Find the queue info KeyValuePair <CoreDispatcher, QueueInstanceInfo> pair; lock (_lock) { pair = _dispatcherToOperationQueueInfo.First(p => p.Value.queueInstance == queue); } // Decrement number of root views pair.Value.rootViewCount--; if (queue != MainUIViewOperationQueue) { if (pair.Value.rootViewCount == 0) { lock (_lock) { // We can remove this queue and then destroy _dispatcherToOperationQueueInfo.Remove(pair.Key); } // Simulate an OnDestroy from the correct dispatcher thread // (OnResume/OnSuspend/OnDestroy have this thread affinity, all other methods do enqueuings in a thread safe manner) return(DispatcherHelpers.CallOnDispatcher(pair.Key, () => { queue.OnDestroy(); return true; })); } else { return(Task.CompletedTask); } } else { return(Task.CompletedTask); } }