本文整理匯總了C#中System.Threading.Thread.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Thread.ToString方法的具體用法?C# Thread.ToString怎麽用?C# Thread.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.ToString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RunTest
public void RunTest()
{
StreamWriter output = new StreamWriter("ThreadSafeGraphTest.txt");
try {
Console.SetOut(output);
Console.WriteLine("## Thread Safe Graph Test");
Console.WriteLine("# Testing with " + this._threads + " Threads and " + this._repeats + " Repeats");
Console.WriteLine();
List<Thread> threads = new List<Thread>();
for (int i = 0; i < this._threads; i++)
{
Thread t = new Thread(new ThreadStart(Test));
threads.Add(t);
}
foreach (Thread t in threads)
{
t.Start();
}
//Wait for Finish
while (true)
{
int activeThreads = 0;
foreach (Thread t in threads)
{
if (t.ThreadState != ThreadState.Stopped)
{
activeThreads++;
}
//Do some reading of the Graph directly from Triples property
IUriNode thread = this._g.CreateUriNode(new Uri("http://threads.org/" + t.ManagedThreadId));
int count = 0;
foreach (Triple tri in this._g.Triples)
{
if (tri.Subject.Equals(thread))
{
count++;
}
}
Console.WriteLine("Currently there are " + count + " Triples in the Graph produced by Thread #" + t.ManagedThreadId);
Console.WriteLine("Currently there are " + this._g.Nodes.Count + " Nodes in the Graph");
}
if (activeThreads > 0)
{
Thread.Sleep(100);
}
else
{
break;
}
}
//Output the end result
Console.WriteLine();
Console.WriteLine("Final Graph contains the following Triples");
Console.WriteLine();
foreach (Triple t in this._g.Triples)
{
Console.WriteLine(t.ToString());
}
} finally {
output.Close();
}
}