Skip to content

Commit d3782bd

Browse files
committed
Use DispatcherPriority.Background for JoinableTaskFactory in tests
1 parent 306d960 commit d3782bd

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

THIRD-PARTY-NOTICES.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,30 @@ Unless required by applicable law or agreed to in writing, software distributed
2121
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
2222
CONDITIONS OF ANY KIND, either express or implied. See the License for the
2323
specific language governing permissions and limitations under the License.
24+
25+
License notice for Microsoft.VisualStudio.Threading
26+
---------------------------------------------------
27+
28+
Microsoft.VisualStudio.Threading
29+
Copyright (c) Microsoft Corporation
30+
All rights reserved.
31+
32+
MIT License
33+
34+
Permission is hereby granted, free of charge, to any person obtaining a copy
35+
of this software and associated documentation files (the "Software"), to deal
36+
in the Software without restriction, including without limitation the rights
37+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38+
copies of the Software, and to permit persons to whom the Software is
39+
furnished to do so, subject to the following conditions:
40+
41+
The above copyright notice and this permission notice shall be included in all
42+
copies or substantial portions of the Software.
43+
44+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50+
SOFTWARE.

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/AbstractIdeIntegrationTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests
66
using System;
77
using System.Threading.Tasks;
88
using System.Windows;
9+
using System.Windows.Threading;
910
using Microsoft.VisualStudio.Shell.Interop;
1011
using Microsoft.VisualStudio.Threading;
12+
using Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Threading;
1113
using Xunit;
1214

1315
[VsTestSettings(UIThread = true)]
@@ -57,7 +59,7 @@ private set
5759
{
5860
_joinableTaskContext = value;
5961
_joinableTaskCollection = value.CreateCollection();
60-
_joinableTaskFactory = value.CreateFactory(_joinableTaskCollection);
62+
_joinableTaskFactory = value.CreateFactory(_joinableTaskCollection).WithPriority(Application.Current.Dispatcher, DispatcherPriority.Background);
6163
}
6264
}
6365
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE.txt in the project root for license information.
3+
4+
namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests.Threading
5+
{
6+
using System.Threading;
7+
using System.Windows.Threading;
8+
using Microsoft;
9+
using Microsoft.VisualStudio.Threading;
10+
11+
// JoinableTaskFactory.WithPriority is available in later releases of vs-threading, but we reference 1.2.0.0 for
12+
// compatibility with Visual Studio 2013.
13+
// https://github.com/Microsoft/vs-threading/pull/142
14+
internal static class JoinableTaskFactoryExtensions
15+
{
16+
internal static JoinableTaskFactory WithPriority(this JoinableTaskFactory joinableTaskFactory, Dispatcher dispatcher, DispatcherPriority priority)
17+
{
18+
Requires.NotNull(joinableTaskFactory, nameof(joinableTaskFactory));
19+
Requires.NotNull(dispatcher, nameof(dispatcher));
20+
21+
return new DispatcherJoinableTaskFactory(joinableTaskFactory, dispatcher, priority);
22+
}
23+
24+
private class DispatcherJoinableTaskFactory : DelegatingJoinableTaskFactory
25+
{
26+
private readonly Dispatcher _dispatcher;
27+
private readonly DispatcherPriority _priority;
28+
29+
public DispatcherJoinableTaskFactory(JoinableTaskFactory innerFactory, Dispatcher dispatcher, DispatcherPriority priority)
30+
: base(innerFactory)
31+
{
32+
_dispatcher = dispatcher;
33+
_priority = priority;
34+
}
35+
36+
protected override void PostToUnderlyingSynchronizationContext(SendOrPostCallback callback, object state)
37+
{
38+
_dispatcher.BeginInvoke(_priority, callback, state);
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)