From 8106691d7c718de8699e71187a39b4b4ead3ec5a Mon Sep 17 00:00:00 2001 From: Stephanie Anderl <46726333+sanderl@users.noreply.github.com> Date: Fri, 26 Jul 2019 11:51:01 -0700 Subject: [PATCH] Fixed issue where UI Responsive events were not fired (#603) * Fixed the WindowIdLog so that it is updated when a new WindowCreated event is fired * Updated the windowidlog check in LogWindowCreated to use IsWindowIdInLog --- src/CalcViewModel/ApplicationViewModel.cpp | 2 +- src/CalcViewModel/Common/TraceLogger.cpp | 23 +++++++++++----------- src/CalcViewModel/Common/TraceLogger.h | 6 +++--- src/Calculator/Views/Calculator.xaml.cpp | 2 +- src/Calculator/Views/MainPage.xaml.cpp | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp index edec2a4..25c3703 100644 --- a/src/CalcViewModel/ApplicationViewModel.cpp +++ b/src/CalcViewModel/ApplicationViewModel.cpp @@ -163,7 +163,7 @@ void ApplicationViewModel::OnModeChanged() } else { - TraceLogger::GetInstance().LogWindowCreated(m_mode); + TraceLogger::GetInstance().LogWindowCreated(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); } RaisePropertyChanged(ClearMemoryVisibilityPropertyName); diff --git a/src/CalcViewModel/Common/TraceLogger.cpp b/src/CalcViewModel/Common/TraceLogger.cpp index 2232771..ddf4186 100644 --- a/src/CalcViewModel/Common/TraceLogger.cpp +++ b/src/CalcViewModel/Common/TraceLogger.cpp @@ -104,24 +104,17 @@ namespace CalculatorApp #pragma endregion // return true if windowId is logged once else return false - bool TraceLogger::UpdateWindowIdLog(int windowId) + bool TraceLogger::IsWindowIdInLog(int windowId) { // Writer lock for the windowIdLog resource reader_writer_lock::scoped_lock lock(s_traceLoggerLock); - if (windowIdLog.find(windowId) == windowIdLog.end()) - { - return false; - } - if (windowIdLog[windowId] == false) - { - windowIdLog[windowId] = true; - return true; - } - else + if (find(windowIdLog.begin(), windowIdLog.end(), windowId) == windowIdLog.end()) { return false; } + + return true; } void TraceLogger::LogVisualStateChanged(ViewMode mode, wstring_view state) const @@ -139,8 +132,14 @@ namespace CalculatorApp LogLevel2Event(EVENT_NAME_VISUAL_STATE_CHANGED, fields); } - void TraceLogger::LogWindowCreated(ViewMode mode) const + void TraceLogger::LogWindowCreated(ViewMode mode, int windowId) { + // store windowId in windowIdLog which says we have logged mode for the present windowId. + if (!IsWindowIdInLog(windowId)) + { + windowIdLog.push_back(windowId); + } + if (!GetTraceLoggingProviderEnabled()) return; diff --git a/src/CalcViewModel/Common/TraceLogger.h b/src/CalcViewModel/Common/TraceLogger.h index 8b3c56b..77201ff 100644 --- a/src/CalcViewModel/Common/TraceLogger.h +++ b/src/CalcViewModel/Common/TraceLogger.h @@ -44,9 +44,9 @@ namespace CalculatorApp void LogButtonUsage(); void LogDateCalculationModeUsed(bool AddSubtractMode); void UpdateWindowCount(size_t windowCount = 0); - bool UpdateWindowIdLog(int windowId); + bool IsWindowIdInLog(int windowId); void LogVisualStateChanged(CalculatorApp::Common::ViewMode mode, std::wstring_view state) const; - void LogWindowCreated(CalculatorApp::Common::ViewMode mode) const; + void LogWindowCreated(CalculatorApp::Common::ViewMode mode, int windowId); void LogConverterInputReceived(CalculatorApp::Common::ViewMode mode) const; void LogNavBarOpened() const; @@ -73,7 +73,7 @@ namespace CalculatorApp winrt::Windows::Foundation::Diagnostics::LoggingChannel g_calculatorProvider; std::vector buttonLog; - std::map windowIdLog; + std::vector windowIdLog; GUID sessionGuid; size_t currentWindowCount = 0; diff --git a/src/Calculator/Views/Calculator.xaml.cpp b/src/Calculator/Views/Calculator.xaml.cpp index 34dda10..2545830 100644 --- a/src/Calculator/Views/Calculator.xaml.cpp +++ b/src/Calculator/Views/Calculator.xaml.cpp @@ -135,7 +135,7 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^) WeakReference weakThis(this); this->Dispatcher->RunAsync( CoreDispatcherPriority::Normal, ref new DispatchedHandler([weakThis]() { - if (TraceLogger::GetInstance().UpdateWindowIdLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) + if (TraceLogger::GetInstance().IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) { auto refThis = weakThis.Resolve(); if (refThis != nullptr) diff --git a/src/Calculator/Views/MainPage.xaml.cpp b/src/Calculator/Views/MainPage.xaml.cpp index 36b1b7b..3762f15 100644 --- a/src/Calculator/Views/MainPage.xaml.cpp +++ b/src/Calculator/Views/MainPage.xaml.cpp @@ -251,7 +251,7 @@ void MainPage::OnPageLoaded(_In_ Object ^, _In_ RoutedEventArgs ^ args) // Delay load things later when we get a chance. this->Dispatcher->RunAsync( CoreDispatcherPriority::Normal, ref new DispatchedHandler([]() { - if (TraceLogger::GetInstance().UpdateWindowIdLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) + if (TraceLogger::GetInstance().IsWindowIdInLog(ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()))) { AppLifecycleLogger::GetInstance().LaunchUIResponsive(); AppLifecycleLogger::GetInstance().LaunchVisibleComplete();