Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET MVC
I have this code that sends out sms notifications to subscribers (about 60,000 subscribers) I keep getting the error System.InvalidOperationException Invalid attempt to read when no data is present. What am I doing wrongly. The code is below. Error is thrown at the beginning of the parallel foreach Parallel.ForEach(accounts, options, x =>
var sw = new Stopwatch();
            var networkSettings = ops.GetNetworkSettings().ToDictionary(x => x.NetworkID, x => x.BillingURL);
            var serviceIds = serviceRepository.All.Where(x=>x.Status);
            //var blastMsgs = new Dictionary<int, Blast>();

            var currTime = DateTime.Now.TimeOfDay;
            foreach (var item in serviceIds)
                var termTime = item.TermTime;
                var termTimeCeiling = currTime.Add(TimeSpan.FromMinutes(15));
                var termTimeFloor = currTime.Add(TimeSpan.FromMinutes(-15));
                if (termTime < termTimeFloor || termTime > termTimeCeiling) continue;
                var activeEntry = entryRepository.GetMessage(item.ServiceId);
                if (activeEntry == null) continue;
                var accounts = accountRepository.SubscribersByServ(item.ServiceId);
                log.Debug("entry is: "+activeEntry.Msg);
                log.Debug("num of accounts: "+accounts.Count());
                log.Debug("service id is: "+item.ServiceId);
                var options = new ParallelOptions {MaxDegreeOfParallelism = 200};
                var count = 0;
                Parallel.ForEach(accounts, options, x =>
                                                            Thread.CurrentThread.IsBackground = false;
                                                            lock (log)
                                                                var msg = new OutboundMessage
                                                                                  Message = activeEntry.Msg,
                                                                                  PhoneNumber = x.PhoneNumber,
                                                                                  SenderId = item.Sender,
                                                                                  NetworkId = x.NetworkId
                                                                if (!ops.DoBilling(msg, item.CampaignId.ToString(), networkSettings)) return;
                                                                Interlocked.Increment(ref count);
                                                                log.Debug("current bill count is: "+count);
                log.Debug("Service Id: " + item.CampaignId);
                log.Debug("Bill count is " + count);
            log.Debug("total bill time: "+sw.Elapsed.TotalMinutes+" minutes");
Posted 20-Feb-13 0:14am
S. M. Ahasan Habib at 20-Feb-13 5:35am
you need to debug the code and address which line of code throw InvalidOperationException and capture exception details and post that.
Aman.A at 20-Feb-13 6:57am
its obviously an issue with the multi-threading code you have. for some reason, the locking is not working i.e. one thread is trying to read some data that the other thread was meant to write but couldn't get to it due to contention and hence the "no data present" error. IMO atleast.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 532
1 Maciej Los 450
2 Sergey Alexandrovich Kryukov 421
3 CPallini 200
4 Peter Leow 190
0 Sergey Alexandrovich Kryukov 6,888
1 OriginalGriff 5,342
2 Peter Leow 3,962
3 Mika Wendelius 2,850
4 CHill60 2,748

Advertise | Privacy | Mobile
Web04 | 2.8.150224.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100