Exemple #1
0
        public static IChangeToken GetOrAddFileChangeToken(string fullname, ConcurrentDictionary <string, ChangeTokenInfo> fileTokenLookup)
        {
            var pattern = NormalizePath(fullname);

            ChangeTokenInfo tokenInfo;

            if (!fileTokenLookup.TryGetValue(fullname, out tokenInfo))
            {
                var cancellationTokenSource = new CancellationTokenSource();
                var cancellationChangeToken = new CancellationChangeToken(cancellationTokenSource.Token);
                tokenInfo = new ChangeTokenInfo(cancellationTokenSource, cancellationChangeToken);
                tokenInfo = fileTokenLookup.GetOrAdd(fullname, tokenInfo);
            }

            IChangeToken changeToken = tokenInfo.ChangeToken;

            return(changeToken);
        }
Exemple #2
0
        public static void CancelToken(ChangeTokenInfo matchInfo)
        {
            if (matchInfo.TokenSource.IsCancellationRequested)
            {
                return;
            }

            Task.Run(() =>
            {
                try
                {
                    matchInfo.TokenSource.Cancel();
                }
                catch
                {
                }
            });
        }