本文整理汇总了C#中System.Threading.CancellationToken.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationToken.GetHashCode方法的具体用法?C# CancellationToken.GetHashCode怎么用?C# CancellationToken.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.CancellationToken
的用法示例。
在下文中一共展示了CancellationToken.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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;
}