<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re : Parallel Loop in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3727204#M52128</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try using Parallel Linq, but it would only work with ObjectId collections not while opening them to get entities, so the benefit won't be so large.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, here's an example from the code you posted:&lt;/P&gt;&lt;P&gt;C#&lt;/P&gt;&lt;PRE&gt;            string[] classes = {"ARC", "CIRCLE", "LINE", "LWPOLYLINE", "POINT", "REGION"};
            ObjectId[] ids;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr =
                    (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                ids = btr
                    .Cast&amp;lt;ObjectId&amp;gt;()
                    .Where(id =&amp;gt; ((Entity)tr.GetObject(id, OpenMode.ForRead)).Layer == LayerVal)
                    .ToArray();
                tr.Commit();
            }
            iMax = ids.Length;
            iUtil = ids
                .AsParallel()
                .Where(id =&amp;gt; classes.Contains(id.ObjectClass.DxfName))
                .Count();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VB&lt;/P&gt;&lt;PRE&gt;            Dim classes As String() = {"ARC", "CIRCLE", "LINE", "LWPOLYLINE", "POINT", "REGION"}
            Dim ids As ObjectId()
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim btr As BlockTableRecord = _
                    DirectCast(tr.GetObject( _
                            SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead), BlockTableRecord)
                ids = btr _
                    .Cast(Of ObjectId)() _
                    .Where(Function(id) DirectCast(tr.GetObject(id, OpenMode.ForRead), Entity).Layer = LayerVal) _
                    .ToArray()
                tr.Commit()
            End Using

            iMax = ids.Length
            iUtil = ids _
                .AsParallel() _
                .Where(Function(id) classes.Contains(id.ObjectClass.DxfName)) _
                .Count()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Dec 2012 11:47:10 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2012-12-07T11:47:10Z</dc:date>
    <item>
      <title>Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3726470#M52126</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to change my source code from "For Each" to "Parallel.Foreach" as to increase processing by using Threads!&lt;/P&gt;&lt;P&gt;Each time, I've failed in changing this code and my net searching were unsucceeded!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my source with "For Each" loop:&lt;/P&gt;&lt;PRE&gt;Using acTrans = acCurDb.TransactionManager.StartTransaction()
    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead)

             For Each acObjId As ObjectId In acBlkTblRec
                    Dim MyEnt As Entity = acTrans.GetObject(acObjId, OpenMode.ForRead)
                    If MyEnt.Layer = LayerVal Then

                        'Nombre d'objets dans le calque séléctionné'
                        iMax += 1

                        'Nombre d'objets à traiter dans le calque séléctionné'
                        Select Case acObjId.ObjectClass.DxfName
                            Case "ARC", "CIRCLE", "LINE", "LWPOLYLINE", "POINT", "REGION"
                                iUtil += 1
                        End Select

                    End If
                Next acObjId
End Using&lt;/PRE&gt;&lt;P&gt;I know that "Parallel.Foreach" deal with "IEnumerable Class" but i'm really lost!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea!?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2012 20:55:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3726470#M52126</guid>
      <dc:creator>MGOMKD</dc:creator>
      <dc:date>2012-12-06T20:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3726658#M52127</link>
      <description>&lt;P&gt;Sorry for the bad news, but the AutoCAD API isn't thread safe. You can get away with multithreaded apps if you only access the API from the main thread, but that's not what you're doing in your example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2012 22:49:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3726658#M52127</guid>
      <dc:creator>StephenPreston</dc:creator>
      <dc:date>2012-12-06T22:49:31Z</dc:date>
    </item>
    <item>
      <title>Re : Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3727204#M52128</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try using Parallel Linq, but it would only work with ObjectId collections not while opening them to get entities, so the benefit won't be so large.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, here's an example from the code you posted:&lt;/P&gt;&lt;P&gt;C#&lt;/P&gt;&lt;PRE&gt;            string[] classes = {"ARC", "CIRCLE", "LINE", "LWPOLYLINE", "POINT", "REGION"};
            ObjectId[] ids;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr =
                    (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                ids = btr
                    .Cast&amp;lt;ObjectId&amp;gt;()
                    .Where(id =&amp;gt; ((Entity)tr.GetObject(id, OpenMode.ForRead)).Layer == LayerVal)
                    .ToArray();
                tr.Commit();
            }
            iMax = ids.Length;
            iUtil = ids
                .AsParallel()
                .Where(id =&amp;gt; classes.Contains(id.ObjectClass.DxfName))
                .Count();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VB&lt;/P&gt;&lt;PRE&gt;            Dim classes As String() = {"ARC", "CIRCLE", "LINE", "LWPOLYLINE", "POINT", "REGION"}
            Dim ids As ObjectId()
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim btr As BlockTableRecord = _
                    DirectCast(tr.GetObject( _
                            SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead), BlockTableRecord)
                ids = btr _
                    .Cast(Of ObjectId)() _
                    .Where(Function(id) DirectCast(tr.GetObject(id, OpenMode.ForRead), Entity).Layer = LayerVal) _
                    .ToArray()
                tr.Commit()
            End Using

            iMax = ids.Length
            iUtil = ids _
                .AsParallel() _
                .Where(Function(id) classes.Contains(id.ObjectClass.DxfName)) _
                .Count()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2012 11:47:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3727204#M52128</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-07T11:47:10Z</dc:date>
    </item>
    <item>
      <title>Re : Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3729732#M52129</link>
      <description>&lt;P&gt;Sorry to learn it doesn't work! I hope it will with another API and Framework version!?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot Gilles, I will work on your Source Code soon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Are you french Gilles?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2012 13:18:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3729732#M52129</guid>
      <dc:creator>MGOMKD</dc:creator>
      <dc:date>2012-12-10T13:18:37Z</dc:date>
    </item>
    <item>
      <title>Re : Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3730472#M52130</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;MGO_MKD a écrit&amp;nbsp;:&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;Thanks a lot Gilles, I will work on your Source Code soon.&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Are you french Gilles?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You're welcome.&lt;/P&gt;&lt;P&gt;Yes, I'm French.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2012 18:40:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3730472#M52130</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-10T18:40:29Z</dc:date>
    </item>
    <item>
      <title>Re : Parallel Loop</title>
      <link>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3730690#M52131</link>
      <description>&lt;P&gt;Salut Gilles!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Je suis également français, ça fait plaisir de ne pas se sentir seul!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2012 20:13:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/parallel-loop/m-p/3730690#M52131</guid>
      <dc:creator>MGOMKD</dc:creator>
      <dc:date>2012-12-10T20:13:14Z</dc:date>
    </item>
  </channel>
</rss>

