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

Remove the two-argument form of AsyncLoader.DoAsync<T> #4726

Merged
merged 1 commit into from
Apr 2, 2018

Conversation

sharwell
Copy link
Member

The two-argument form of DoAsync<T> didn't seem to provide substantial advantages over JTF. This pull request converts the few uses to a more direct JTF approach and requires DoAsync<T> users pass the third argument.

📝 If accepted, please do not rebase or squash this pull request during the merge.

@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #4726 into master will decrease coverage by <.01%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##           master    #4726      +/-   ##
==========================================
- Coverage    28.5%   28.49%   -0.01%     
==========================================
  Files         510      510              
  Lines       41080    41107      +27     
  Branches     5924     5929       +5     
==========================================
+ Hits        11708    11713       +5     
- Misses      28857    28879      +22     
  Partials      515      515
Impacted Files Coverage Δ
GitCommands/AsyncLoader.cs 80% <ø> (ø) ⬆️
GitUI/FilterBranchHelper.cs 25.86% <0%> (-1.42%) ⬇️
GitUI/CommandsDialogs/FormBrowse.cs 4.98% <0%> (-0.03%) ⬇️
GitExtUtils/GitUI/ControlThreadingExtensions.cs 86.76% <81.25%> (-9.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb7b987...4e46fb4. Read the comment docs.

@drewnoakes
Copy link
Member

Looks like good stuff but there's some new APIs in there for me so I'm not sure I can give a proper review without some more research.

(result) => toolStripSplitStash.Text = string.Format(_stashCount.Text, result,
result != 1 ? _stashPlural.Text : _stashSingular.Text));
});
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are on UI thread here, can we drop alwaysYield: true?

Copy link
Member Author

@sharwell sharwell Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Yes, alwaysYield only has an effect if you are already on the target thread. I'll update both all three cases for this PR and add assertions to the calling method so the current thread is clear. (I made no other changes in the amended commit relative to the initial review.)

@@ -961,6 +968,8 @@ private void UpdateStashCount()

private void CheckForMergeConflicts()
{
ThreadHelper.ThrowIfNotOnUIThread();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to know little more about the need of putting this assertion. By the first rule we should put it when we require to be on the UI thread. Every method that accesses UI controls has to meet such a requirement. Should all that methods include this assertion? I know that in this case when dropping alwaysYield: true you want to be sure that we are on the UI thread and there is no need to explicitly require to always yield. However, this method accesses UI controls so we can be pretty sure that it can be called only from the UI thread. On the other hand there is UpdateBranchNameDisplayAsync method which does not assert we are on the UI thread nor it requests to alwaysYield. I think we should create a wiki page that explains when it is required to assert that a method is running on UI thread.

Copy link
Member Author

@sharwell sharwell Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn on how to handle this in the long run. In #4728, an empty file was added called vs-threading.TypesRequiringMainThread.txt. One could imagine adding the following line to this file:

System.Windows.Forms.*

However, this produced an incredible burden for development (I think 7,000 new warnings, including many warnings for things that are not actually problematic). For now I'm trying to include the assertion when it's relevant in new code, but we haven't started to leverage its full capability yet - and probably shouldn't until we figure out the usability issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which does not assert we are on the UI thread nor it requests to alwaysYield

The use of alwaysYield is not characteristic of other cases where vs-threading is used. For us, it serves two purposes:

  1. It allowed me to preserve the behavior of code during a transition to vs-threading. By preserving existing behavior, we did not have to examine each case in detail to determine if alwaysYield should be specified or not.
  2. It hides the latency we have in GitCommands, which does not implement asynchronous commands even though they are run in a separate process. Once GitCommands moves to async code, the need for alwaysYield will likely disappear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jbialobr jbialobr merged commit bfd250b into gitextensions:master Apr 2, 2018
@sharwell sharwell deleted the do-async branch April 2, 2018 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants