-
Notifications
You must be signed in to change notification settings - Fork 2
fix how we update the properties in environments page after an operation #2950
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using System.Threading.Tasks; | ||
using DevHome.Common.Environments.Models; | ||
using Microsoft.UI.Xaml.Media.Imaging; | ||
using Microsoft.VisualBasic; | ||
bbonaby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using Microsoft.Windows.DevHome.SDK; | ||
using Serilog; | ||
|
||
|
@@ -131,7 +132,7 @@ public static EnvironmentsCallToActionData UpdateCallToActionText(int providerCo | |
} | ||
|
||
/// <summary> | ||
/// Safely remove all items from an observable collection. | ||
/// Safely removes all items from an observable collection and replaces them with new items. | ||
/// </summary> | ||
/// <remarks> | ||
/// There can be random COM exceptions due to using the "Clear()" method in an observable collection. This method | ||
|
@@ -140,19 +141,32 @@ public static EnvironmentsCallToActionData UpdateCallToActionText(int providerCo | |
/// this method is used to remove all items individually from the end of the collection to the beginning of the collection. | ||
/// </remarks> | ||
/// <typeparam name="T">Type of objects that the collection contains</typeparam> | ||
/// <param name="collection">An observable collection that contains zero to N elements</param> | ||
public static void RemoveAllItems<T>(ObservableCollection<T> collection) | ||
/// <param name="collectionToUpdate">An observable collection that contains zero to N elements that will have its contents replaced</param> | ||
/// <param name="listWithUpdates">A list that contains zero to N elements whose elements will be added to collectionToUpdate</param> | ||
/// <returns> | ||
/// True only if we successfully replaced all items in the collection. False otherwise. | ||
/// </returns> | ||
public static bool RemoveAllItemsAnReplace<T>(ObservableCollection<T> collectionToUpdate, List<T> listWithUpdates) | ||
bbonaby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
try | ||
{ | ||
for (var i = collection.Count - 1; i >= 0; i--) | ||
for (var i = collectionToUpdate.Count - 1; i >= 0; i--) | ||
{ | ||
collection.RemoveAt(i); | ||
collectionToUpdate.RemoveAt(i); | ||
} | ||
|
||
for (var i = 0; i < listWithUpdates.Count; i++) | ||
{ | ||
collectionToUpdate.Add(listWithUpdates[i]); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These loops fire OnCollectionChanged events for every operation which is inefficient and can make UX less responsive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using that requires adding the |
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_log.Error(ex, "Unable to remove items from the collection"); | ||
} | ||
|
||
return false; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.