void ShowInternal(DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh) { Debug.Assert(asyncWorkerContext == null); UIContext = tabContent.CreateUIContext(documentTabUIContextLocator); var cachedUIContext = UIContext; Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this); cachedUIContext.DocumentTab = this; Debug.Assert(cachedUIContext.DocumentTab == this); Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this); tabContent.DocumentTab = this; Debug.Assert(tabContent.DocumentTab == this); UpdateTitleAndToolTip(); DnSpyEventSource.Log.ShowDocumentTabContentStart(); var showCtx = new ShowContext(cachedUIContext, isRefresh); tabContent.OnShow(showCtx); bool asyncShow = false; if (tabContent is AsyncDocumentTabContent asyncTabContent) { if (asyncTabContent.NeedAsyncWork(showCtx)) { asyncShow = true; var ctx = new AsyncWorkerContext(); asyncWorkerContext = ctx; var asyncShowCtx = new AsyncShowContext(showCtx, ctx); Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken) .ContinueWith(t => { bool canShowAsyncOutput = ctx == asyncWorkerContext && cachedUIContext.DocumentTab == this && UIContext == cachedUIContext; if (asyncWorkerContext == ctx) { asyncWorkerContext = null; } ctx.Dispose(); asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput)); bool success = !t.IsFaulted && !t.IsCanceled; OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } else { asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult()); } } if (!asyncShow) { OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent); } documentTabService.OnNewTabContentShown(this); }
void ShowInternal(DocumentTabContent tabContent, object uiState, Action<ShowTabContentEventArgs> onShownHandler, bool isRefresh) { Debug.Assert(asyncWorkerContext == null); UIContext = tabContent.CreateUIContext(documentTabUIContextLocator); var cachedUIContext = UIContext; Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this); cachedUIContext.DocumentTab = this; Debug.Assert(cachedUIContext.DocumentTab == this); Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this); tabContent.DocumentTab = this; Debug.Assert(tabContent.DocumentTab == this); UpdateTitleAndToolTip(); var showCtx = new ShowContext(cachedUIContext, isRefresh); tabContent.OnShow(showCtx); bool asyncShow = false; var asyncTabContent = tabContent as AsyncDocumentTabContent; if (asyncTabContent != null) { if (asyncTabContent.NeedAsyncWork(showCtx)) { asyncShow = true; var ctx = new AsyncWorkerContext(); asyncWorkerContext = ctx; var asyncShowCtx = new AsyncShowContext(showCtx, ctx); Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken) .ContinueWith(t => { bool canShowAsyncOutput = ctx == asyncWorkerContext && cachedUIContext.DocumentTab == this && UIContext == cachedUIContext; if (asyncWorkerContext == ctx) asyncWorkerContext = null; ctx.Dispose(); asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput)); bool success = !t.IsFaulted && !t.IsCanceled; OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } else asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult()); } if (!asyncShow) OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent); documentTabService.OnNewTabContentShown(this); }