本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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;
}