Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JobLesson06.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JobLesson06Part01", "JobLesson06Part01\JobLesson06Part01.csproj", "{531E9871-B0A3-4958-A0BE-382D7687042C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JobLesson06Part01", "JobLesson06Part01\JobLesson06Part01.csproj", "{531E9871-B0A3-4958-A0BE-382D7687042C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
60 changes: 37 additions & 23 deletions JobLesson06Part01/Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
using System;
using System.IO;
using System.Diagnostics;

namespace JobLesson06Part01
{
internal class Program
{
static void Main(string[] args)
static int Main(string[] args)
{
string log = string.Empty; // пустая строка - ""
log += $"Начало работы приложения";
try
{
int x = 10;
int y = x / 0;
log += $"{Environment.NewLine}Результат деления: {y}";
}
catch
{
log += $"{Environment.NewLine}Во время выполнения деления произошла ошибка";
}
finally
{
File.WriteAllText("log.txt", log);
}
try
//Написать консольное приложение Task Manager,
//которое выводит на экран запущенные процессы и
//позволяет завершить указанный процесс.
//Предусмотреть возможность завершения процессов с помощью указания его ID
//или имени процесса.
//В качестве примера можно использовать консольные утилиты
//Windows tasklist и taskkill.




Process[] processes = Process.GetProcesses();

for (int i = 0; i < processes.Length; i++)
{
object x = null;
int y = (int)x / 0;
Process current = processes[i];
Console.WriteLine($"{current.ProcessName}, ID Процесса:{current.Id}");
}
catch (DivideByZeroException)
Console.WriteLine("Введите Имя процесса который нужно завершить -");
string killProcess = Console.ReadLine();
Console.WriteLine("Или введите ID процесса который нужно завершить -");
int killIdProcess = Int32.Parse(Console.ReadLine());
for (int i = 0; i < processes.Length; i++)
{
Console.WriteLine("Деление на ноль");
Process current = processes[i];
if (current.ProcessName == killProcess)
{
current.Kill();
Console.WriteLine($"Процесс -{current.ProcessName} был завершен");
}
if (current.Id == killIdProcess)
{
current.Kill();
Console.WriteLine($"Процесс -{current.Id} был завершен");
}
}
return 0;

}

}
}
8 changes: 8 additions & 0 deletions JobLesson06Part01/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"JobLesson06Part01": {
"commandName": "Project",
"commandLineArgs": "start"
}
}
}
73 changes: 73 additions & 0 deletions JobLesson06Part01/Занятие6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Calculate(5, 10, null);

}

static int Calculate(int a, int b, object foo)
{
/*
*�������������� ��������
*������ � ��������� (���������� ��������� � ������
*������ � ���������
*������ � ������� � ���������� (���������� Input Output )
*������ � ��
*������ � �����
*/

//string log = String.Empty;
//log +=$"������ ������ ����������";
//try
//{


int result = (b / a) + foo.GetHashCode();
return result;
// log += $"{Environment.NewLine}��������� �������:{result}";
//}
//catch(DivideByZeroException divedeByZeroExeption)
//{
// log += $"{Environment.NewLine}�� ����� ������� ��������� ������ - divedeByZeroExeption";
// Console.WriteLine("You can");
//}
//catch(NullReferenceException nullReferenceException)
//{
// log += $"{Environment.NewLine}�� ����� ������� ��������� ������ - nullReferenceException";
// Console.WriteLine("Null ref");
//}
//catch(Exception exception)
//{
// log += $"{Environment.NewLine}�� ����� ������� ��������� ������";
// Console.WriteLine(exception.Message);
//}
////catch
////{
//// log += $"{Environment.NewLine}�� ����� ������� ��������� ������";

////}
//finally
//{
// File.WriteAllText("log.txt", log);
//}
//Console.WriteLine("No result!");
//return 0;


//if (args.Length>0)
//{
// string firstarg = args[0];
// if (firstarg =="start")
// {
// Console.WriteLine("start algo");
// return;
// }
// if (firstarg=="stop")
// {
// Console.WriteLine("stop algo");
// return;
// }
//}
//return -1;
}
public class NotValidCalculationArgumentsExeption : Exception
{

}
16 changes: 16 additions & 0 deletions Варианты.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var procList = Process.GetProcesses();
foreach (var proc in procList)
{
Console.WriteLine($"{proc.Id} {proc.ProcessName} {proc.BasePriority}");
}
Console.Write("name = ");
var name = Console.ReadLine();
try
{
procList.First(p => p.ProcessName.ToLower() == name.ToLower()).Kill();
Console.WriteLine($"{name} deleted!");
}
catch (InvalidOperationException)
{
Console.WriteLine($"Process {name} not found!");
}
1 change: 1 addition & 0 deletions Урок 6 Задания.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�������� ���������� ���������� Task Manager, ������� ������� �� ����� ���������� �������� � ��������� ��������� ��������� �������. ������������� ����������� ���������� ��������� � ������� �������� ��� ID ��� ����� ��������. � �������� ������� ����� ������������ ���������� ������� Windows tasklist � taskkill.