From 690b0d05c6c6a2f248abd9a323f2ee4bb6a22e5c Mon Sep 17 00:00:00 2001 From: syneffort Date: Thu, 29 Feb 2024 17:11:12 +0900 Subject: [PATCH] call event --- EffectiveCSharp/EffectiveCSharp.sln | 25 ++++++++++++++++ .../EffectiveCSharp/EffectiveCSharp.csproj | 10 +++++++ .../LanguageComponent/CallEvent.cs | 30 +++++++++++++++++++ EffectiveCSharp/EffectiveCSharp/Program.cs | 15 ++++++++++ 4 files changed, 80 insertions(+) create mode 100644 EffectiveCSharp/EffectiveCSharp.sln create mode 100644 EffectiveCSharp/EffectiveCSharp/EffectiveCSharp.csproj create mode 100644 EffectiveCSharp/EffectiveCSharp/LanguageComponent/CallEvent.cs create mode 100644 EffectiveCSharp/EffectiveCSharp/Program.cs diff --git a/EffectiveCSharp/EffectiveCSharp.sln b/EffectiveCSharp/EffectiveCSharp.sln new file mode 100644 index 0000000..a01922f --- /dev/null +++ b/EffectiveCSharp/EffectiveCSharp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EffectiveCSharp", "EffectiveCSharp\EffectiveCSharp.csproj", "{1B79263C-F9E0-4FAC-8550-E91173EB3A2F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1B79263C-F9E0-4FAC-8550-E91173EB3A2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B79263C-F9E0-4FAC-8550-E91173EB3A2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B79263C-F9E0-4FAC-8550-E91173EB3A2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B79263C-F9E0-4FAC-8550-E91173EB3A2F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {18E619C9-0514-4336-A32F-36E7B1205A92} + EndGlobalSection +EndGlobal diff --git a/EffectiveCSharp/EffectiveCSharp/EffectiveCSharp.csproj b/EffectiveCSharp/EffectiveCSharp/EffectiveCSharp.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/EffectiveCSharp/EffectiveCSharp/EffectiveCSharp.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/EffectiveCSharp/EffectiveCSharp/LanguageComponent/CallEvent.cs b/EffectiveCSharp/EffectiveCSharp/LanguageComponent/CallEvent.cs new file mode 100644 index 0000000..6c8afc2 --- /dev/null +++ b/EffectiveCSharp/EffectiveCSharp/LanguageComponent/CallEvent.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EffectiveCSharp.LanguageComponent +{ + internal class CallEvent + { + public event EventHandler Event; + + public void Work() + { + int cnt = 0; + while (cnt < 10) + { + cnt++; + RaiseUpdate(cnt.ToString()); + + Thread.Sleep(1000); + } + } + + private void RaiseUpdate(string contents) + { + Event?.Invoke(this, contents); + } + } +} diff --git a/EffectiveCSharp/EffectiveCSharp/Program.cs b/EffectiveCSharp/EffectiveCSharp/Program.cs new file mode 100644 index 0000000..31ed4be --- /dev/null +++ b/EffectiveCSharp/EffectiveCSharp/Program.cs @@ -0,0 +1,15 @@ +using EffectiveCSharp.LanguageComponent; + +namespace EffectiveCSharp +{ + internal class Program + { + static void Main(string[] args) + { + CallEvent callEvent = new CallEvent(); + callEvent.Event += (s, e) => Console.WriteLine(e); + callEvent.Work(); + } + + } +}