Skip to content
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

EditNetSpell: Avoid ObjectDisposedException #11160

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions GitUI/SpellChecker/EditNetSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,16 @@ private void ToggleAutoCompletion()
}

InitializeAutoCompleteWordsTask();
CancellationToken cancellationToken = _autoCompleteCancellationTokenSource.Token;

Validates.NotNull(_autoCompleteListTask);
Validates.NotNull(_spelling);

ThreadHelper.JoinableTaskFactory.RunAsync(
async () =>
{
var words = await _autoCompleteListTask.GetValueAsync();
await this.SwitchToMainThreadAsync(_autoCompleteCancellationTokenSource.Token);
IEnumerable<AutoCompleteWord> words = await _autoCompleteListTask.GetValueAsync(cancellationToken);
await this.SwitchToMainThreadAsync(cancellationToken);

_spelling.AddAutoCompleteWords(words.Select(x => x.Word));
});
Expand Down Expand Up @@ -887,16 +888,17 @@ private void InitializeAutoCompleteWordsTask()
{
CancelAutoComplete();
_autoCompleteCancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = _autoCompleteCancellationTokenSource.Token;
_autoCompleteListTask = new AsyncLazy<IEnumerable<AutoCompleteWord>?>(
async () =>
{
await TaskScheduler.Default.SwitchTo(alwaysYield: true);

var subTasks = _autoCompleteProviders.Select(p => p.GetAutoCompleteWordsAsync(_autoCompleteCancellationTokenSource.Token)).ToArray();
Task<IEnumerable<AutoCompleteWord>>[] subTasks = _autoCompleteProviders.Select(p => p.GetAutoCompleteWordsAsync(cancellationToken)).ToArray();
try
{
var results = await Task.WhenAll(subTasks);
return results.SelectMany(result => result).Distinct().ToList();
IEnumerable<AutoCompleteWord>[] results = await Task.WhenAll(subTasks);
return results.SelectMany(result => result).Distinct();
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -1016,8 +1018,8 @@ private void UpdateOrShowAutoComplete(bool calledByUser)
return;
}

var autoCompleteList = ThreadHelper.JoinableTaskFactory.Run(() => _autoCompleteListTask.GetValueAsync());
var list = autoCompleteList.Where(x => x.Matches(word)).Distinct().ToList();
IEnumerable<AutoCompleteWord> autoCompleteList = ThreadHelper.JoinableTaskFactory.Run(_autoCompleteListTask.GetValueAsync);
IReadOnlyList<AutoCompleteWord> list = autoCompleteList.Where(x => x.Matches(word)).ToList();

if (list.Count == 0)
{
Expand Down
Loading