Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:06:37+00:00 2026-06-17T15:06:37+00:00

I often find it’s not really specified what exact collection is causing this type

  • 0

I often find it’s not really specified what exact collection is causing this type of exception. Is that true or should it be obvious? Perhaps I just don’t understand how to interpret the exception message properly..

Specifically I wonder about this one. What is the collection it refers to?

The parameter of the event delegate is simply (object sender), and the events raised passes null parameter. Though the class itself that raises the event inherits a list:

public class TimeSerie : List<BarData>

Is it clear here if the “collection” refers to the object that raises the event, or can it be another object? Can it be, say a collection of event handlers to a method that is being dynamically changed? Or would that create a different exception?

    ************** Exception Text **************
System.InvalidOperationException: 
Collection was modified; enumeration operation may not execute.
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at System.Windows.Forms.Control.Invoke(Delegate method)
   at SomeNameSpace.SomeUserControl.InvokeOnUpdateHistory(Object sender) in D:\SomePath\SomeUserControl.cs:line 5179
   at OtherNameSpace.OtherClass.TimeSerie.HistoryUpdateEventHandler.Invoke(Object sender)

Exception occurs in UserControl:

    public class SomeUserControl 

    private void InvokeOnUpdate(object sender)
    {
    this.Invoke(new GenericInvoker(Method));   // << Exception here!
    }

    private void Method() {...}

EDIT:
Added some code. A bit simplified, but think it includes relevant bits.

private void Method() 
{
            if (this.instrument == null) return;  
            UnRegisterTimeSerieHandlers(this.ts);

            this.ts = instrument.DataSeries.GetTimeSerieByInterval(interval);
            if (ts != null)
            { 
                RegisterTimeseriesHandlers(ts);
                ClearAndLoadAllHistory();
            }
}

    private void UnRegisterTimeSerieHandlers(TimeSerie ts)
    {
        if (ts != null)
        {
            ts.TickUpdate -= InvokeUpdateCurrentBar;
            ts.NewBarUpdate -= InvokeUpdateNewBar;
            ts.HistoryUpdate -= InvokeOnUpdateHistory;
            this.ts = null;
        }
    }

    private void RegisterTimeseriesHandlers(TimeSerie ts)
    {
        ts.TickUpdate += InvokeUpdateCurrentBar;
        ts.NewBarUpdate += InvokeUpdateNewBar;
        ts.HistoryUpdate += InvokeOnUpdateHistory;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:06:38+00:00Added an answer on June 17, 2026 at 3:06 pm

    Yes, the cause of an exception can be quite hard to diagnose when you use Control.Invoke(). The problem is that it catches the exception when it occurs on the UI thread and re-throws it in your worker thread. Necessarily so, your worker thread needs to know that the return value of Invoke() is not usable. The inevitable side-effect is that you lose the Holy Stack Trace that tells you where it blew up and how it got there.

    If you can repro the problem when you have a debugger attached then use Debug + Exceptions, tick the Thrown checkbox for CLR Exceptions. The debugger stops when the exception is thrown, giving you a good statement location and a call stack to look at.

    If not then do consider using Control.BeginInvoke() instead. This is a fire-and-forget version of Invoke() so if the invoked method throws then that exception will be raised on the UI thread and you’ll get an accurate stack trace with it.

    In general you always want to favor BeginInvoke(). It doesn’t cause the worker thread to stall, it avoids many deadlock scenarios and give good exception feedback. Using Invoke() is generally a mistake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often find the need to include away and present type visual states that
I often find myself wanting to debug CSS layout issues that involve DOM changes
I often find myself needing reference to an object that is several objects away,
I often find myself with a list of disconnected Linq2Sql objects or keys that
I often find myself with a file that has one number per line. I
I often find myself executing commands like this at bash : history | grep
I often find that attributes can be too large. Sometimes it feels like the
I often find this pattern in Haskell code: options :: MVar OptionRecord options =
I often find this strange CDATA tag in XML files: <![CDATA[some stuff]]> I have
I often find the following type of incremental definition useful: (define (foo) (display bar))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.