当前位置: 首页>>代码示例>>C#>>正文


C# CancellationTokenSource.GetHashCode方法代码示例

本文整理汇总了C#中System.Threading.CancellationTokenSource.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationTokenSource.GetHashCode方法的具体用法?C# CancellationTokenSource.GetHashCode怎么用?C# CancellationTokenSource.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.CancellationTokenSource的用法示例。


在下文中一共展示了CancellationTokenSource.GetHashCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CancellationToken_GetHashCode

        public static void CancellationToken_GetHashCode()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken ct = cts.Token;
            int hash1 = cts.GetHashCode();
            int hash2 = cts.Token.GetHashCode();
            int hash3 = ct.GetHashCode();

            Assert.Equal(hash1, hash2);
            Assert.Equal(hash2, hash3);

            CancellationToken defaultUnsetToken1 = new CancellationToken();
            CancellationToken defaultUnsetToken2 = new CancellationToken();
            int hashDefaultUnset1 = defaultUnsetToken1.GetHashCode();
            int hashDefaultUnset2 = defaultUnsetToken2.GetHashCode();
            Assert.Equal(hashDefaultUnset1, hashDefaultUnset2);

            CancellationToken defaultSetToken1 = new CancellationToken(true);
            CancellationToken defaultSetToken2 = new CancellationToken(true);
            int hashDefaultSet1 = defaultSetToken1.GetHashCode();
            int hashDefaultSet2 = defaultSetToken2.GetHashCode();
            Assert.Equal(hashDefaultSet1, hashDefaultSet2);

            Assert.NotEqual(hash1, hashDefaultUnset1);
            Assert.NotEqual(hash1, hashDefaultSet1);
            Assert.NotEqual(hashDefaultUnset1, hashDefaultSet1);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:27,代码来源:CancellationTokenTests.cs

示例2: RunAsync

        public Task<ProcessResults> RunAsync(ProcessStartInfo processStartInfo, CancellationTokenSource cancellationToken)
        {
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError = true;

            var tcs = new TaskCompletionSource<ProcessResults>();

            var standardOutput = new List<string>();
            var standardError = new List<string>();

            var process = new Process
            {
                StartInfo = processStartInfo,
                EnableRaisingEvents = true
            };

            process.OutputDataReceived += (sender, args) =>
            {
                if (args.Data != null)
                {
                    standardOutput.Add(args.Data);
                }
            };

            process.ErrorDataReceived += (sender, args) =>
            {
                if (args.Data != null)
                {
                    standardError.Add(args.Data);
                }
            };

            
            cancellationToken.Token.ThrowIfCancellationRequested();

            _log.Debug("Registering cancellation for " + cancellationToken.GetHashCode());

            cancellationToken.Token.Register(() =>
            {
                tcs.TrySetCanceled();
                KillProcessAndChildren(process.Id);
            });


               process.Exited += (sender, args) =>
               {
                   tcs.TrySetResult(new ProcessResults(process, standardOutput, standardError));
               };

            if (process.Start() == false)
            {
                tcs.TrySetException(new InvalidOperationException("Failed to start process"));
            }

            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            return tcs.Task;
        }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:60,代码来源:Processes.cs

示例3: QueueTask

 private Int32 QueueTask(Func<Action<IWindow>, Int32, CancellationTokenSource, Task> taskCreator, Action<IWindow> callback, Int32 timeout)
 {
     var cts = new CancellationTokenSource();
     taskCreator.Invoke(callback, timeout, cts);
     _document.AttachReference(cts);
     return cts.GetHashCode();
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:7,代码来源:Window.cs

示例4: CancellationToken_GetHashCode

        private static bool CancellationToken_GetHashCode()
        {
            TestHarness.TestLog("* CancellationTokenTests.CancellationToken_GetHashCode()");
            bool passed = true;

            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken ct = cts.Token;
            int hash1 = cts.GetHashCode();
            int hash2 = cts.Token.GetHashCode();
            int hash3 = ct.GetHashCode();

            passed &= TestHarnessAssert.AreEqual(hash1, hash2, "[1]Hashes should be equal.");
            passed &= TestHarnessAssert.AreEqual(hash2, hash3, "[2]Hashes should be equal.");


            CancellationToken defaultUnsetToken1 = new CancellationToken();
            CancellationToken defaultUnsetToken2 = new CancellationToken();
            int hashDefaultUnset1 = defaultUnsetToken1.GetHashCode();
            int hashDefaultUnset2 = defaultUnsetToken2.GetHashCode();
            passed &= TestHarnessAssert.AreEqual(hashDefaultUnset1, hashDefaultUnset2, "[3]Hashes should be equal.");


            CancellationToken defaultSetToken1 = new CancellationToken(true);
            CancellationToken defaultSetToken2 = new CancellationToken(true);
            int hashDefaultSet1 = defaultSetToken1.GetHashCode();
            int hashDefaultSet2 = defaultSetToken2.GetHashCode();
            passed &= TestHarnessAssert.AreEqual(hashDefaultSet1, hashDefaultSet2, "[4]Hashes should be equal.");



            passed &= TestHarnessAssert.AreNotEqual(hash1, hashDefaultUnset1, "[5]Hashes should be different.");
            passed &= TestHarnessAssert.AreNotEqual(hash1, hashDefaultSet1, "[6]Hashes should be different.");
            passed &= TestHarnessAssert.AreNotEqual(hashDefaultUnset1, hashDefaultSet1, "[7]Hashes should be different.");


            return passed;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:37,代码来源:CancellationTokenTests.cs


注:本文中的System.Threading.CancellationTokenSource.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。