static void Main(string[] args) { var getprocess = Process.GetProcesses(); Console.WriteLine(st + "Task1" + sw); using (StreamWriter sw = new StreamWriter("file.txt", false, Encoding.Default)) { try { foreach (var proc in getprocess) { sw.WriteLine("Process: " + proc.Id); sw.WriteLine("Name of process: " + proc.ProcessName); sw.WriteLine("Priority of process: " + proc.BasePriority); sw.WriteLine("Time of start process: " + proc.StartTime); sw.WriteLine("Total using time of process: " + proc.TotalProcessorTime); sw.WriteLine(); } } catch { } } Console.WriteLine("If you need information about process of 1 task pls check file.txt"); Console.WriteLine(str); Console.WriteLine(st + "Task2" + sw); Console.WriteLine(); using (StreamWriter text = new StreamWriter("Domain.txt")) { //This app analysis var thisAppDomain = Thread.GetDomain(); text.WriteLine($"Name: {thisAppDomain.FriendlyName}"); text.WriteLine($"Setup Information: {thisAppDomain.SetupInformation.ToString()}"); text.WriteLine("Assemblies:"); foreach (var item in thisAppDomain.GetAssemblies()) { text.WriteLine(" " + item.FullName.ToString()); } //Domain AppDomain secondaryDomain = AppDomain.CreateDomain("Secondary domain"); //build load event secondaryDomain.AssemblyLoad += Domain_AssemblyLoad; //domain unload event secondaryDomain.DomainUnload += SecondaryDomain_DomainUnload; Console.WriteLine($"Domain: {secondaryDomain.FriendlyName}"); secondaryDomain.Load(new AssemblyName("System.Data")); Assembly[] assemblies = secondaryDomain.GetAssemblies(); foreach (Assembly asm in assemblies) { Console.WriteLine(asm.GetName().Name); } //unload domain AppDomain.Unload(secondaryDomain); Console.WriteLine(str); } Console.WriteLine(st + "Task3" + sw); Thread NumbersThread = new Thread(new ParameterizedThreadStart(WriteNums)); NumbersThread.Start(10); NumbersThread.Suspend(); NumbersThread.Name = "Info about MyThread"; Console.WriteLine("Priority: " + NumbersThread.Priority); Thread.Sleep(100); Console.WriteLine("Name: " + NumbersThread.Name); Thread.Sleep(100); Console.WriteLine("ID: " + NumbersThread.ManagedThreadId); Console.WriteLine("List of eazy numbers:"); Thread.Sleep(1000); NumbersThread.Resume(); Thread.Sleep(1000); Console.WriteLine(str); Console.WriteLine(st + "Task4" + sw); Console.WriteLine("Consistently:"); OddEven.DoItConsistently(); Thread.Sleep(4000); Console.WriteLine("One by one:"); OddEven.DoItOneByOne(); Thread.Sleep(4000); Console.WriteLine(str); Console.WriteLine(st + "Task5" + sw); TimerCallback timerCallback = new TimerCallback(WhatTimeIsIt); Timer timer = new Timer(timerCallback, null, 0, 1000); Thread.Sleep(5000); void WhatTimeIsIt(object obj) { Console.WriteLine($"It's {DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}"); } Console.WriteLine(str); }
static void Main(string[] args) { #region Task 1: Get all processes and their info using (StreamWriter file = new StreamWriter("allProcesses.txt")) { var allProcesses = Process.GetProcesses(); foreach (var process in allProcesses) { file.WriteLine($"{process.Id}: {process.ProcessName}"); file.WriteLine($" Priority: {process.BasePriority}"); //file.WriteLine($"{process.Id}: {process.ProcessName}; Priority: {process.BasePriority}; " + // $"Start time: {process.StartTime};"); } } #endregion #region Task 2: Get and investigate domain of this app; Add another assembly using (StreamWriter text = new StreamWriter("ThisAppDomain.txt")) { //New assembly LovelyClasses.TheLoveliest theLoveliest = new LovelyClasses.TheLoveliest(); LovelyClasses.AnotherLovelyClass anotherLovelyClass = new LovelyClasses.AnotherLovelyClass(); var theLoveliestSpeach = theLoveliest.Speak(); var anotherLovelySpeach = anotherLovelyClass.Speak(); //This app analysis var thisAppDomain = Thread.GetDomain(); text.WriteLine($"Name: {thisAppDomain.FriendlyName}"); text.WriteLine($"Setup Information: {thisAppDomain.SetupInformation.ToString()}"); text.WriteLine("Assemblies:"); foreach (var item in thisAppDomain.GetAssemblies()) { text.WriteLine(" " + item.FullName.ToString()); } //New domain var lovelyDomain = AppDomain.CreateDomain("LovelyClasses"); var lovelyAssembly = AssemblyName.GetAssemblyName("LovelyClasses.dll"); lovelyDomain.Load(lovelyAssembly); AppDomain.Unload(lovelyDomain); } #endregion #region Task 3: Thread task Console.WriteLine("--------- Task 3 ----------"); Thread NumbersThread = new Thread(new ParameterizedThreadStart(WriteNums)); NumbersThread.Start(7); Thread.Sleep(2000); NumbersThread.Suspend(); Console.WriteLine("\n--------------------"); Console.WriteLine("Its priority: " + NumbersThread.Priority); Thread.Sleep(100); Console.WriteLine("Its name: " + NumbersThread.Name); Thread.Sleep(100); Console.WriteLine("Its ID: " + NumbersThread.ManagedThreadId); Console.WriteLine("---------------------"); Thread.Sleep(1000); NumbersThread.Resume(); Thread.Sleep(2000); void WriteNums(object number) //Method for another thread { int num = (int)number; using (StreamWriter numbers = new StreamWriter("Numbers.txt")) { for (int i = 0; i < num; i++) { numbers.WriteLine(i); Console.WriteLine(i); Thread.Sleep(500); } } } #endregion #region Task 4: Odd and even nums in file via two threads Console.WriteLine("Press any key"); Console.ReadKey(); Console.WriteLine("\n------------- Task 4 --------------"); Console.WriteLine("Consistently:"); OddEven.DoItConsistently(); Thread.Sleep(4000); Console.WriteLine("Press any key"); Console.ReadKey(); Console.WriteLine("\nOne by one:"); OddEven.DoItOneByOne(); #endregion #region Task 5: Smth with timers Thread.Sleep(4000); Console.WriteLine("\nPress any key"); Console.ReadKey(); TimerCallback timerCallback = new TimerCallback(WhatTimeIsIt); Timer timer = new Timer(timerCallback, null, 0, 1000); Thread.Sleep(5000); void WhatTimeIsIt(object obj) { Console.WriteLine($"It's {DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}"); } #endregion }
static void Main(string[] args) { //1.Вывкчти все процессы и инфу о них using (StreamWriter file = new StreamWriter("allProcesses.txt")) { var allProcesses = Process.GetProcesses(); foreach (var process in allProcesses) { file.WriteLine($"{process.Id}: {process.ProcessName}"); file.WriteLine($" Priority: {process.BasePriority}"); } } //2.исследовать текущий домен using (StreamWriter text = new StreamWriter("ThisAppDomain.txt")) { var thisAppDomain = Thread.GetDomain(); text.WriteLine($"Name: {thisAppDomain.FriendlyName}"); text.WriteLine($"Setup Information: {thisAppDomain.SetupInformation.ToString()}"); text.WriteLine("Assemblies:"); foreach (var item in thisAppDomain.GetAssemblies()) { text.WriteLine(" " + item.FullName.ToString()); } } //Task 3: Thread task Console.WriteLine("--------- Task 3 ----------"); Thread NumbersThread = new Thread(new ParameterizedThreadStart(WriteNums)); NumbersThread.Start(7); //Thread.Sleep(3000); NumbersThread.Suspend(); Console.WriteLine("\n--------------------"); Console.WriteLine("Its priority: " + NumbersThread.Priority); Thread.Sleep(100); Console.WriteLine("Its name: " + NumbersThread.Name); Thread.Sleep(100); Console.WriteLine("Its ID: " + NumbersThread.ManagedThreadId); Console.WriteLine("---------------------"); Thread.Sleep(1000); NumbersThread.Resume(); Thread.Sleep(2000); void WriteNums(object number) //Method for another thread { int num = (int)number; using (StreamWriter numbers = new StreamWriter("Numbers.txt")) { for (int i = 0; i < num; i++) { numbers.WriteLine(i); Console.WriteLine(i); Thread.Sleep(500); } } } //4. 2 потока Console.ReadKey(); Console.WriteLine("\n------------- Task 4 --------------"); Console.WriteLine("Consistently:"); OddEven.DoItConsistently(); Thread.Sleep(4000); Console.ReadKey(); Console.WriteLine("\nOne by one:"); OddEven.DoItOneByOne(); //5.таймер Thread.Sleep(4000); Console.WriteLine("\nPress any key"); Console.ReadKey(); TimerCallback timerCallback = new TimerCallback(WhatTimeIsIt); Timer timer = new Timer(timerCallback, null, 0, 1000); Thread.Sleep(5000); void WhatTimeIsIt(object obj) { Console.WriteLine($"It's {DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}"); } Console.ReadLine(); }