Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random error while using Parallel.ForEach #18

Open
bluedoom opened this issue Jul 27, 2022 · 0 comments
Open

Random error while using Parallel.ForEach #18

bluedoom opened this issue Jul 27, 2022 · 0 comments

Comments

@bluedoom
Copy link

System.AggregateException: One or more errors occurred. (An item with the same key has already been added. Key: 2350882391344)
---> System.ArgumentException: An item with the same key has already been added. Key: 2350882391344
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at FreeImageAPI.FreeImage.OpenMultiBitmapFromStream(Stream stream, FREE_IMAGE_FORMAT& format, FREE_IMAGE_LOAD_FLAGS flags)
at FreeImageAPI.FreeImageBitmap.LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
at FreeImageAPI.FreeImageBitmap..ctor(String filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
at FreeImageAPI.FreeImageBitmap..ctor(String filename, FREE_IMAGE_LOAD_FLAGS flags)
at FreeImageAPI.FreeImageBitmap..ctor(String filename)
at FreeImageAPI.FreeImageBitmap.FromFile(String filename)

Parallel.ForEach(Directory.GetFiles(dir, "*.png", SearchOption.TopDirectoryOnly), (path) =>
{
    using (var bitmap = FreeImageAPI.FreeImageBitmap.FromFile(path))
    {
        //readonly operation
    }
});

framework:
.net 6.0
both macOS and windows will get the error, but not frequently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant