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

经过测试,还是重复 #5

Closed
yuxueliang opened this issue Dec 29, 2018 · 3 comments
Closed

经过测试,还是重复 #5

yuxueliang opened this issue Dec 29, 2018 · 3 comments

Comments

@yuxueliang
Copy link

var blockingCollection = new BlockingCollection();
List tasks = new List();
for (int i = 0; i < 100; i++)
{
var task = Task.Run(() =>
{

                for (int j = 0; j < 10000; j++)
                {

                    blockingCollection.Add(new Generator(1, DateTime.MinValue).Next());
                }
            });

            tasks.Add(task);
        }

        Task.WaitAll(tasks.ToArray());

        Console.WriteLine(blockingCollection.Distinct().Count());

        Console.ReadKey();
@hanslai
Copy link

hanslai commented Dec 29, 2018

I guess, I will translate the issue title. What @yuxueliang said was: “After some test, it will still generated duplicated Ids.”

@jhabjan
Copy link

jhabjan commented Feb 8, 2019

There is nothing wrong with this library and it works as expected without creating duplicates. Issue here is your poor implementation. Why would you create new instance of Generator for every iteration? With example you provided result is as expected.

@mschuler
Copy link
Owner

As @jhabjan said, you must not create new instances of Generator with the same Instance ID (in your case 1). If you create multiple generators, use unique instance id's.

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

4 participants