예제 #1
0
 public async Task AwaitRegKeyChange_WatchSubtree()
 {
     using (var test = new RegKeyTest())
     {
         using (var subKey = test.CreateSubKey())
         {
             Task changeWatcherTask = test.Key.WaitForChangeAsync(watchSubtree: true, cancellationToken: test.FinishedToken);
             subKey.SetValue("subkeyValueName", "b");
             await changeWatcherTask;
         }
     }
 }
예제 #2
0
 public async Task AwaitRegKeyChange_KeyDeleted()
 {
     using (var test = new RegKeyTest())
     {
         using (var subKey = test.CreateSubKey())
         {
             Task changeWatcherTask = subKey.WaitForChangeAsync(watchSubtree: true, cancellationToken: test.FinishedToken);
             test.Key.DeleteSubKey(Path.GetFileName(subKey.Name));
             await changeWatcherTask;
         }
     }
 }
예제 #3
0
 public async Task AwaitRegKeyChange_WatchSubtree()
 {
     Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
     using (var test = new RegKeyTest())
     {
         using (var subKey = test.CreateSubKey())
         {
             Task changeWatcherTask = test.Key.WaitForChangeAsync(watchSubtree: true, cancellationToken: test.FinishedToken);
             subKey.SetValue("subkeyValueName", "b");
             await changeWatcherTask;
         }
     }
 }
예제 #4
0
        public async Task AwaitRegKeyChange_NoWatchSubtree()
        {
            using (var test = new RegKeyTest())
            {
                using (var subKey = test.CreateSubKey())
                {
                    Task changeWatcherTask = test.Key.WaitForChangeAsync(watchSubtree: false, cancellationToken: test.FinishedToken);
                    subKey.SetValue("subkeyValueName", "b");

                    // We do not expect changes to sub-keys to complete the task, so give a bit of time to confirm
                    // the task doesn't complete.
                    Task completedTask = await Task.WhenAny(changeWatcherTask, Task.Delay(AsyncDelay));

                    Assert.NotSame(changeWatcherTask, completedTask);
                }
            }
        }
예제 #5
0
        public async Task AwaitRegKeyChange_CallingThreadDestroyed()
        {
            using (var test = new RegKeyTest())
            {
                // Start watching and be certain the thread that started watching is destroyed.
                // This simulates a more common case of someone on a threadpool thread watching
                // a key asynchronously and then the .NET Threadpool deciding to reduce the number of threads in the pool.
                Task watchingTask = null;
                var  thread       = new Thread(() =>
                {
                    watchingTask = test.Key.WaitForChangeAsync(cancellationToken: test.FinishedToken);
                });
                thread.Start();
                thread.Join();

                // Verify that the watching task is still watching.
                Task completedTask = await Task.WhenAny(watchingTask, Task.Delay(AsyncDelay));

                Assert.NotSame(watchingTask, completedTask);
                test.CreateSubKey().Dispose();
                await watchingTask;
            }
        }