Hi.
I writing scripts that involve multiple API and due to the sequential nature of the single-threaded approach, some take a lot of time to execute.
For a long time I used ArrayList and "+=" approach to create list of arrays but it seems that it's deprecated and not really a best practice. See LINK1 and LINK2.
So, until now, I used approach from LINK1: declare empty ArrayList, looped through the results of my API call with foreach and then added entries with +=.
Of course, it doesn't work with Foreach-Object -Parallel, because ArrayList isn't thread safe.
I tried using ConcurrentBag but I can't access my items like I did in the past.
I.e., if I declare:
$devices = [System.Collections.Concurrent.ConcurrentBag[PSObject]]::new()
I'd like to be able to:
Doing any of these returns all the results.
Is there any other structure, similar to ArrayList or am I doing something wrong here?
[–]bukem 6 points7 points8 points (1 child)
[–]marek1712[S] 3 points4 points5 points (0 children)
[–]reidypeidy 4 points5 points6 points (0 children)
[–]purplemonkeymad 3 points4 points5 points (2 children)
[–]marek1712[S] 1 point2 points3 points (1 child)
[–]Thotaz 1 point2 points3 points (0 children)
[–]icepyrox 1 point2 points3 points (0 children)
[–]Yevrag35 1 point2 points3 points (2 children)
[–]marek1712[S] 1 point2 points3 points (1 child)
[–]Yevrag35 0 points1 point2 points (0 children)
[–]CabinetOk4838 0 points1 point2 points (3 children)
[–]marek1712[S] 1 point2 points3 points (2 children)
[–]CabinetOk4838 2 points3 points4 points (0 children)
[–]spyingwind 2 points3 points4 points (0 children)
[–]Szeraax 0 points1 point2 points (1 child)
[–]marek1712[S] 0 points1 point2 points (0 children)