当前位置: 首页>>代码示例>>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;未经允许,请勿转载。