diff --git a/HomeWork16/HomeWork16.sln b/HomeWork16/HomeWork16.sln new file mode 100644 index 0000000..123bcf8 --- /dev/null +++ b/HomeWork16/HomeWork16.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HomeWork16", "HomeWork16\HomeWork16.csproj", "{06850D53-AB66-49E1-B8E5-A526298E8098}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {06850D53-AB66-49E1-B8E5-A526298E8098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06850D53-AB66-49E1-B8E5-A526298E8098}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06850D53-AB66-49E1-B8E5-A526298E8098}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06850D53-AB66-49E1-B8E5-A526298E8098}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2782D84C-2B16-4A80-863F-A156C3A9BE16} + EndGlobalSection +EndGlobal diff --git a/HomeWork16/HomeWork16/Enums/State.cs b/HomeWork16/HomeWork16/Enums/State.cs new file mode 100644 index 0000000..3273f48 --- /dev/null +++ b/HomeWork16/HomeWork16/Enums/State.cs @@ -0,0 +1,7 @@ +namespace HomeWork16.Enums; + +public enum State +{ + OK, + Cancel +} diff --git a/HomeWork16/HomeWork16/HomeWork16.csproj b/HomeWork16/HomeWork16/HomeWork16.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/HomeWork16/HomeWork16/HomeWork16.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/HomeWork16/HomeWork16/MessageBox.cs b/HomeWork16/HomeWork16/MessageBox.cs new file mode 100644 index 0000000..d8c477f --- /dev/null +++ b/HomeWork16/HomeWork16/MessageBox.cs @@ -0,0 +1,22 @@ +using HomeWork16.Enums; + +namespace HomeWork16; + +public delegate void MessageBoxDelegate (State state); + +internal class MessageBox +{ + public event MessageBoxDelegate? NotifyState; + public async Task OpenAsync() + { + Console.WriteLine("Window is open"); + + await Task.Delay(3000); + + Console.WriteLine("Window was closed by the user"); + + var randomState = (State)new Random().Next(0, 2); + + NotifyState?.Invoke(randomState); + } +} diff --git a/HomeWork16/HomeWork16/Program.cs b/HomeWork16/HomeWork16/Program.cs new file mode 100644 index 0000000..915e50e --- /dev/null +++ b/HomeWork16/HomeWork16/Program.cs @@ -0,0 +1,27 @@ +using HomeWork16.Enums; + +namespace HomeWork16; + +internal class Program +{ + static void Main(string[] args) + { + var messageBox = new MessageBox(); + + messageBox.NotifyState += (State state) => + { + if (state == State.OK) + { + Console.WriteLine($"{state} - the operation has been confirmed"); + } + else + { + Console.WriteLine($"{state} - the operation was rejected"); + } + }; + + var task = Task.Run(() => messageBox.OpenAsync()); + + task.Wait(); + } +}