Skip to content

Commit 1ebc426

Browse files
author
msftbot[bot]
authored
Create separate instances of GazePointer per (UI) thread, (#3590)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> ## Fixes # Fixes #3589 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <- Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> One GazePointer object per application. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> One GazePointer object per (UI) thread. ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information
2 parents 0fbe036 + c40e3b4 commit 1ebc426

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

Microsoft.Toolkit.Uwp.Input.GazeInteraction/GazePointer.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Diagnostics;
88
using System.Linq;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using Windows.Devices.Input.Preview;
1112
using Windows.Foundation;
@@ -298,20 +299,9 @@ internal int CursorRadius
298299
/// </summary>
299300
public bool IsAlwaysActivated { get; set; }
300301

301-
private static GazePointer _instance = null;
302+
private static ThreadLocal<GazePointer> _instance = new ThreadLocal<GazePointer>(() => new GazePointer());
302303

303-
internal static GazePointer Instance
304-
{
305-
get
306-
{
307-
if (_instance == null)
308-
{
309-
_instance = new GazePointer();
310-
}
311-
312-
return _instance;
313-
}
314-
}
304+
internal static GazePointer Instance => _instance.Value;
315305

316306
internal void AddRoot(int proxyId)
317307
{

0 commit comments

Comments
 (0)