Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Composite 4.1 Bug??

$
0
0
That's not a good idea to use "new Random().Next()" for generating a new random element. It generates a pseudo random sequence, using current time information as an offset, so if you output it a few times in a row, it will also give you the same numbers:

for(int i=0; i<1000; i++) {
         Console.WriteLine(new Random().Next());     
}

1863531641
749895586
749895586
749895586
.....

in your case the reason for the same ID-s to appear was a quicker execution time (because of parallels), so you ended up having the same numbers.
the right way to use the Random class would be to create and use the same instance of it:

private static Random _random = new Random();
....
_random.Next();

About NullReferenceException() on localhost - what do you use to host the site locally? Do you use Visual Studio for hosting the website, or IIS Express?
The built in web server in Visual Studio is flawed in many ways and does not behave the same way as reall IIS does.

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>