--- lang: ja-jp breaks: true --- # C# シグナルを使って非同期処理を行う 2021-10-13 ## CountdownEvent 軽量だとか。 > System.Threading.CountdownEvent > https://qiita.com/rawr/items/6888778b53fc95c41f00#systemthreadingcountdownevent > スレッドの相互作用、またはシグナリング > https://docs.microsoft.com/ja-jp/dotnet/standard/threading/overview-of-synchronization-primitives#thread-interaction-or-signaling > CountdownEvent > https://docs.microsoft.com/ja-jp/dotnet/standard/threading/countdownevent ```csharp= IEnumerable<Data> source = GetData(); using (CountdownEvent e = new CountdownEvent(1)) { // fork work: foreach (Data element in source) { // Dynamically increment signal count. e.AddCount(); ThreadPool.QueueUserWorkItem( delegate(object state) { try { ProcessData(state); } finally { e.Signal(); } }, element ); } e.Signal(); // The first element could be run on this thread. // Join with work. e.Wait(); } // .,. ``` ## ManualResetEvent ###### tags: `C#` `シグナル` `非同期` `マルチスレッド` `CountdownEvent`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up