當前位置: 首頁>>代碼示例>>C#>>正文


C# Thread.ToString方法代碼示例

本文整理匯總了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();
            }
        }
開發者ID:almostEric,項目名稱:DotNetRDF-4.0,代碼行數:70,代碼來源:ThreadSafeGraphTest.cs


注:本文中的System.Threading.Thread.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。