Esempio n. 1
0
        public void DependsOn(CancellationToken dependency, Activator.Options options)
        {
            if (options == Activator.Options.Default && !externalTokens.Contains(dependency))
            {
                externalTokens.Add(dependency);
                if (IsActive)
                {
                    tokenRegistrations.Add(dependency, dependency.Register(Deactivate));           // If already running, don't re-create the CTS, just add this dependency as a stand-alone registration.
                }
            }
            else if (options == Activator.Options.RemoveDependency && externalTokens.Contains(dependency))
            {
                externalTokens.Remove(dependency);
                if (tokenRegistrations.ContainsKey(dependency))
                {
                    tokenRegistrations[dependency].Dispose();                                             // Causes it to become unregistered once more.
                }
                CreateCTS();
                //cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationTokenHelpers.Normalize(externalTokens).Token);
            }

            //var currentToken = cts?.Token ?? CancellationToken.None;
            //cts = CancellationTokenSource.CreateLinkedTokenSource(token, currentToken);
            //cts.Token.Register(Deactivate);
        }
Esempio n. 2
0
 public void DependsOn(CancellationToken token, Activator.Options options = Activator.Options.Default)
 {
     if (token.CanBeCanceled || cts == null)
     {
         cts = CancellationTokenSource.CreateLinkedTokenSource(StopToken, token);
     }
     stopRegistration?.Dispose();
     stopRegistration = cts.Token.Register(Stop);
 }
 public void DependsOn(CancellationToken token, Activator.Options options)
 {
 }
Esempio n. 4
0
 public void DependsOn(CancellationToken token, Activator.Options options = Activator.Options.Default)
 {
     token.Register(Deactivate);
 }