-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DataGrid crash in Sample App #4476
Fix DataGrid crash in Sample App #4476
Conversation
Thanks HEIGE-PCloud for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
@@ -30,6 +31,7 @@ public async Task<IEnumerable<DataGridDataItem>> GetDataAsync() | |||
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri); | |||
IRandomAccessStreamWithContentType randomStream = await file.OpenReadAsync(); | |||
_items = new ObservableCollection<DataGridDataItem>(); | |||
IFormatProvider provider = CultureInfo.InvariantCulture.DateTimeFormat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: Was there a particular reason we didn't want to use this inline or was it to just bubble it up to the top of the function here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure about the cost of calling CultureInfo.InvariantCulture.DateTimeFormat
. Consider it is used in a loop, and put it up top seems harmless...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sergio0694 I'm sure could shed some light here, from my understanding it shouldn't make a difference as it should be optimized by the compiler in either case? Definitely curious now though... Sergio any insights you could shed on this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my benchmark, there is no difference.
using System.Globalization;
string t = "01/01/1900";
const int N = 10000000;
IFormatProvider provider = CultureInfo.InvariantCulture.DateTimeFormat;
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
for (int i = 0; i < N; i ++)
{
DateTimeOffset.Parse(t, provider);
}
watch.Stop();
Console.WriteLine($"Execution Time (top): {watch.ElapsedMilliseconds} ms");
watch.Reset();
watch.Start();
for (int i = 0; i < N; i ++)
{
DateTimeOffset.Parse(t, CultureInfo.InvariantCulture.DateTimeFormat);
}
watch.Stop();
Console.WriteLine($"Execution Time (inline): {watch.ElapsedMilliseconds} ms");
Execution Time (top): 3031 ms
Execution Time (inline): 3002 ms
Execution Time (top): 2978 ms
Execution Time (inline): 3010 ms
Execution Time (top): 2991 ms
Execution Time (inline): 3017 ms
Execution Time (top): 2980 ms
Execution Time (inline): 3003 ms
Execution Time (top): 2964 ms
Execution Time (inline): 3031 ms
Execution Time (top): 3038 ms
Execution Time (inline): 3186 ms
Execution Time (top): 2986 ms
Execution Time (inline): 3022 ms
Execution Time (top): 3073 ms
Execution Time (inline): 3014 ms
I'll move it inline then :)
Signed-off-by: HEIGE-PCloud <[email protected]>
Thanks for fixing this @HEIGE-PCloud! 🦙❤ |
Fixes
Fixes #4475
Use
CultureInfo.InvariantCulture.DateTimeFormat
asIFormatProvider
forDateTimeOffset.Parse
when loading data source for the DataGrid sample to prevent crashing caused by regional settings.PR Type
What kind of change does this PR introduce?
Bugfix
What is the current behavior?
The sample crashes immediately when navigated to the DataGrid sample.
What is the new behavior?
Not crash.
PR Checklist
Please check if your PR fulfills the following requirements:
Other information