- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
ThreadPlayaroundWithPriorities.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Threading;
- namespace Wrox.ProCSharp.ThreadPlayaround
- {
- class EntryPoint
- {
- static int interval;
- static void Main()
- {
- Console.Write("Interval to display results at?> ");
- interval = int.Parse(Console.ReadLine());
- Thread thisThread = Thread.CurrentThread;
- thisThread.Name = "Main Thread";
- ThreadStart workerStart = new ThreadStart(StartMethod);
- Thread workerThread = new Thread(workerStart);
- workerThread.Name = "Worker";
- workerThread.Priority = ThreadPriority.AboveNormal;
- workerThread.Start();
- DisplayNumbers();
- Console.WriteLine("Main Thread Finished");
- Console.ReadLine();
- }
- static void StartMethod()
- {
- DisplayNumbers();
- Console.WriteLine("Worker Thread Finished");
- }
- static void DisplayNumbers()
- {
- Thread thisThread = Thread.CurrentThread;
- string name = thisThread.Name;
- Console.WriteLine("Starting thread: " + name);
- Console.WriteLine(name + ": Current Culture = " + thisThread.CurrentCulture);
- for (int i=1 ; i<= 8*interval ; i++)
- {
- if (i%interval == 0)
- Console.WriteLine(name + ": count has reached " + i);
- }
- }
- }
- }