Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 11020 [details]
I was stress testing ThreadPool to check if it causes issues to my socket connection, and after a while i noticed that Random.NextDouble() in my test just stops producing random numbers. This happens on both iPhone and Simulator. Check the attached project. And see this video: http://www.screencast.com/t/mcC69TXWl
PS: For the ThreadPool, using it for my internal purposes indeed somehow caused lags to my socket connection, as a workaround i simply wrote my own implementation and it worked.
You're accessing the Random instance from multiple threads at the same time, and Random isn't thread-safe.
In fact MSDN  says that you'll get 0 if you do it: "If you don't ensure that the Random object is accessed in a thread-safe way, calls to methods that return random numbers return 0."
If you change your sample to have one Random per thread, it works fine:
static Random rnd;// = new Random();
static void OnNSTimerTick(Foundation.NSTimer Timer)
static void ThreadPoolCallback(object State)
if (rnd == null)
rnd = new Random ();
for (int i = 0; i < 1000000; i++)
double rndValue = rnd.NextDouble();
Thanks for pointing this out, my mistake.