<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>potisan</author_name>
  <author_url>https://blog.hatena.ne.jp/potisan/</author_url>
  <blog_title>potisanのプログラミングメモ</blog_title>
  <blog_url>https://potisan-programming-memo.hatenablog.jp/</blog_url>
  <categories>
    <anon>C#</anon>
  </categories>
  <description>C#における同期処理の知識がBackgroundWorkerやTaskで止まっていたのですが、ParallelとConcurrentBagを使ったら非同期処理を簡単に同期処理に変更できました。マルチスレッドになるのでリソースの同時アクセスには注意が必要ですが、各スレッドでそれぞれファイルを開いて結果を配列やリストにまとめるような処理であればほぼそのまま同期処理にできます。 Paralell.For/ForEachもConcurrentBag（あるいはSystem.Collections.Concurrent名前空間のクラス）もネット上に大量のサンプルがありますが、例えば次のようなコードが書けま…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fpotisan-programming-memo.hatenablog.jp%2Fentry%2F2024%2F10%2F04%2F201206&quot; title=&quot;C# Parallel.For/ForEachとConcurrentBagによる同期化 - potisanのプログラミングメモ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2024-10-04 20:12:06</published>
  <title>C# Parallel.For/ForEachとConcurrentBagによる同期化</title>
  <type>rich</type>
  <url>https://potisan-programming-memo.hatenablog.jp/entry/2024/10/04/201206</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
