Skip to content

Commit c873cda

Browse files
authored
For truly async calls we must maintain our lifetime (1.10) (#5200)
## Change Add forgotten lifetime extension for async function. ## Validation Changed the sample caller to call `FindPackagesAsync`, then destroy the catalog object. CP #5199
1 parent 7f00ea8 commit c873cda

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

src/Microsoft.Management.Deployment/PackageCatalog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
4747
}
4848
winrt::Windows::Foundation::IAsyncOperation<winrt::Microsoft::Management::Deployment::FindPackagesResult> PackageCatalog::FindPackagesAsync(winrt::Microsoft::Management::Deployment::FindPackagesOptions options)
4949
{
50+
auto strong_this = get_strong();
5051
co_await resume_background();
5152
co_return FindPackages(options);
5253
}

src/Microsoft.Management.Deployment/PackageCatalogReference.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
311311
// Check for permissions and get caller info for telemetry
312312
THROW_IF_FAILED(EnsureComCallerHasCapability(Capability::PackageQuery));
313313

314+
auto strong_this = get_strong();
314315
auto report_progress{ co_await winrt::get_progress_token() };
315316
co_await winrt::resume_background();
316317

src/Microsoft.Management.Deployment/PackageManager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
13291329

13301330
::AppInstaller::Repository::Source sourceToAdd = CreateSourceFromOptions(options);
13311331

1332+
auto strong_this = get_strong();
13321333
auto report_progress{ co_await winrt::get_progress_token() };
13331334
co_await winrt::resume_background();
13341335

@@ -1367,6 +1368,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
13671368
auto matchingSource = GetMatchingSource(winrt::to_string(options.Name()));
13681369
THROW_HR_IF(APPINSTALLER_CLI_ERROR_SOURCE_NAME_DOES_NOT_EXIST, !matchingSource.has_value());
13691370

1371+
auto strong_this = get_strong();
13701372
auto report_progress{ co_await winrt::get_progress_token() };
13711373
co_await winrt::resume_background();
13721374

0 commit comments

Comments
 (0)