Ver código fonte

Добавлены примеры из 19 лабораторной

Вадим Королёв 1 ano atrás
pai
commit
e6da9d3ad9

+ 39 - 0
Lab19-2/Lab19-2.csproj

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{A5593396-FC10-4F69-9C94-28B5B0374FBF}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Lab192</RootNamespace>
+    <AssemblyName>Lab19-2</AssemblyName>
+    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>

+ 33 - 0
Lab19-2/Program.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Lab192
+{
+    class Program
+    {
+        static void TaskAction()
+        {
+            Console.WriteLine("TaskAction started");
+            for (int i = 0; i < 5; i++)
+            {
+                Thread.Sleep(1000);
+                Console.WriteLine($"Count: {i}");
+            }
+        }
+        public static void Main(string[] args)
+        {
+            Console.WriteLine("Main thread start!");
+            Task task = new Task(TaskAction);
+            task.Start();
+
+            for (int i = 0; i < 20; i++)
+            {
+                Console.WriteLine(".");
+                Thread.Sleep(500);
+            }
+
+            Console.WriteLine("Main thread stop!");
+        }
+    }
+}

+ 26 - 0
Lab19-2/Properties/AssemblyInfo.cs

@@ -0,0 +1,26 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Lab19-2")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("${AuthorCopyright}")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]

+ 39 - 0
Lab19-3/Lab19-3.csproj

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{85099160-F561-4FC5-94A9-AE35991ECAD0}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Lab193</RootNamespace>
+    <AssemblyName>Lab19-3</AssemblyName>
+    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>

+ 37 - 0
Lab19-3/Program.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Lab193
+{
+    class Program
+    {
+        static void TaskAction()
+        {
+            Console.WriteLine($"TaskAction started. Task ID: {Task.CurrentId}");
+            for (int i = 0; i < 5; i++)
+            {
+                Thread.Sleep(1000);
+                Console.WriteLine($"Task ID: {Task.CurrentId}; Count: {i}");
+            }
+        }
+
+        public static void Main(string[] args)
+        {
+            Console.WriteLine("Main thread start!");
+
+            Task task1 = new Task(TaskAction);
+            Task task2 = new Task(TaskAction);
+            task1.Start();
+            task2.Start();
+
+            for (int i = 0; i < 25; i++)
+            {
+                Console.Write(".");
+                Thread.Sleep(500);
+            }
+
+            Console.WriteLine("Main thread stop!");
+        }
+    }
+}

+ 26 - 0
Lab19-3/Properties/AssemblyInfo.cs

@@ -0,0 +1,26 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Lab19-3")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("${AuthorCopyright}")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]

+ 39 - 0
Lab19-4/Lab19-4.csproj

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{AF65BDEA-C029-477E-938A-02EFCA212A5C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Lab194</RootNamespace>
+    <AssemblyName>Lab19-4</AssemblyName>
+    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>

+ 36 - 0
Lab19-4/Program.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Lab194
+{
+    class Program
+    {
+        static void TaskAction()
+        {
+            Console.WriteLine($"TaskAction started. Task ID: {Task.CurrentId}");
+            for (int i = 0; i < 5; i++)
+            {
+                Thread.Sleep(1000);
+                Console.WriteLine($"Task ID: {Task.CurrentId}; Count: {i}");
+            }
+            Console.WriteLine($"TaskAction ended. Task ID: {Task.CurrentId}");
+        }
+
+        public static void Main(string[] args)
+        {
+            Console.WriteLine("Main thread start!");
+
+            Task task1 = new Task(TaskAction);
+            Task task2 = new Task(TaskAction);
+            task1.Start();
+            task2.Start();
+
+            Console.WriteLine("Waiting...");
+            task1.Wait();
+            task2.Wait();
+
+            Console.WriteLine("Main thread stop!");
+        }
+    }
+}

+ 26 - 0
Lab19-4/Properties/AssemblyInfo.cs

@@ -0,0 +1,26 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Lab19-4")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("${AuthorCopyright}")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]

+ 39 - 0
Lab19/Lab19-1.csproj

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProjectGuid>{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Lab19</RootNamespace>
+    <AssemblyName>Lab19</AssemblyName>
+    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ExternalConsole>true</ExternalConsole>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project>

+ 60 - 0
Lab19/Program.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Concurrent;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Lab19
+{
+    class Program
+    {
+        static BlockingCollection<int> bc;
+
+        static void producer()
+        {
+            for (int i = 0; i < 100; i++)
+            {
+                bc.Add(i * i);
+                Console.WriteLine($"Producer {i * i}");
+            }
+            bc.CompleteAdding();
+        }
+
+        static void consumer()
+        {
+            int i;
+            while (!bc.IsCompleted)
+            {
+                if (bc.TryTake(out i))
+                {
+                    Console.WriteLine($"Consumer {i}");
+                }
+            }
+        }
+
+        public static void Main(string[] args)
+        {
+            bc = new BlockingCollection<int>(4);
+
+            Task ProducerTask = new Task(producer);
+            Task ConsumerTask = new Task(consumer);
+
+            ProducerTask.Start();
+            ConsumerTask.Start();
+
+            try
+            {
+                Task.WaitAll(ConsumerTask, ProducerTask);
+            } 
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex);
+            }
+            finally
+            {
+                ConsumerTask.Dispose();
+                ProducerTask.Dispose();
+                bc.Dispose();
+            }
+        }
+    }
+}

+ 26 - 0
Lab19/Properties/AssemblyInfo.cs

@@ -0,0 +1,26 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Lab19")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("${AuthorCopyright}")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]

+ 24 - 0
MDKlabs.sln

@@ -3,6 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab18", "Lab18\Lab18.csproj", "{2E68FC5F-19D6-4A85-B7E3-0455CE576063}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab19-1", "Lab19\Lab19-1.csproj", "{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab19-2", "Lab19-2\Lab19-2.csproj", "{A5593396-FC10-4F69-9C94-28B5B0374FBF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab19-3", "Lab19-3\Lab19-3.csproj", "{85099160-F561-4FC5-94A9-AE35991ECAD0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab19-4", "Lab19-4\Lab19-4.csproj", "{AF65BDEA-C029-477E-938A-02EFCA212A5C}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|x86 = Debug|x86
@@ -13,6 +21,22 @@ Global
 		{2E68FC5F-19D6-4A85-B7E3-0455CE576063}.Debug|x86.Build.0 = Debug|x86
 		{2E68FC5F-19D6-4A85-B7E3-0455CE576063}.Release|x86.ActiveCfg = Release|x86
 		{2E68FC5F-19D6-4A85-B7E3-0455CE576063}.Release|x86.Build.0 = Release|x86
+		{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}.Debug|x86.ActiveCfg = Debug|x86
+		{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}.Debug|x86.Build.0 = Debug|x86
+		{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}.Release|x86.ActiveCfg = Release|x86
+		{E01D495C-21FF-4FCD-A4BE-76FFA0D0549E}.Release|x86.Build.0 = Release|x86
+		{A5593396-FC10-4F69-9C94-28B5B0374FBF}.Debug|x86.ActiveCfg = Debug|x86
+		{A5593396-FC10-4F69-9C94-28B5B0374FBF}.Debug|x86.Build.0 = Debug|x86
+		{A5593396-FC10-4F69-9C94-28B5B0374FBF}.Release|x86.ActiveCfg = Release|x86
+		{A5593396-FC10-4F69-9C94-28B5B0374FBF}.Release|x86.Build.0 = Release|x86
+		{85099160-F561-4FC5-94A9-AE35991ECAD0}.Debug|x86.ActiveCfg = Debug|x86
+		{85099160-F561-4FC5-94A9-AE35991ECAD0}.Debug|x86.Build.0 = Debug|x86
+		{85099160-F561-4FC5-94A9-AE35991ECAD0}.Release|x86.ActiveCfg = Release|x86
+		{85099160-F561-4FC5-94A9-AE35991ECAD0}.Release|x86.Build.0 = Release|x86
+		{AF65BDEA-C029-477E-938A-02EFCA212A5C}.Debug|x86.ActiveCfg = Debug|x86
+		{AF65BDEA-C029-477E-938A-02EFCA212A5C}.Debug|x86.Build.0 = Debug|x86
+		{AF65BDEA-C029-477E-938A-02EFCA212A5C}.Release|x86.ActiveCfg = Release|x86
+		{AF65BDEA-C029-477E-938A-02EFCA212A5C}.Release|x86.Build.0 = Release|x86
 	EndGlobalSection
 	GlobalSection(MonoDevelopProperties) = preSolution
 		Policies = $0