Сбой визуальной студии! - Коллекция была модифицирована после создания перечисления

Эй, у меня есть usercontrol, который продолжал разбиться моей визуальной студией. Поэтому я пробежал еще один экземпляр VS и отладил другую против, и это то, что я подумал:

Collection was modified after the enumerator was instantiated.

вот мой массив:

    private static Color[] colors = 
    {
        Color.FromArgb(155, 188, 255), //    40000
        Color.FromArgb(156, 189, 255), //    39500
        Color.FromArgb(157, 188, 255), //    39000
        Color.FromArgb(156, 189, 254), //    38500
    };

и вот моя петля, которая вылетает Bussines

    public Heater()
    {
        InitializeComponent();
        this.tarTemp = this.curTemp;
        new Thread(() => UpdateTemp(true)).Start(); 
    }

    private delegate void UpdateTempDelegate(bool loop);
    private void UpdateTemp(bool loop)
    {
        if (lblTemp.InvokeRequired)
        {
            UpdateTempDelegate del = new UpdateTempDelegate(UpdateTemp);
            lblTemp.Invoke(del, loop);
        }
        else
        {
            do
            {
                lblTemp.Text = curTemp + C;
                if (curTemp >= 0)
                {
                    int i = curTemp - 10;
                    if (i < 0)
                        i = 0;
                    if (i > colors.Length - 1)
                        i = colors.Length - 1;
                    this.BackColor = colors[i]; // I'M CRASHING !!!
                }
            } while (loop && !this.Disposing);
        }
    }

линия, которая сбивает визуальный дизайнер-студий Это this.backcolor = цвета [I];

Вот изображение беговых резьб:

Threads

Все темы останавливаются на одной линии ... This.backcolor = цвета [I];

Вот это EventViewer журнал аварии:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
Stack:
   at System.ThrowHelper.ThrowInvalidOperationException(System.ExceptionResource)
   at System.Collections.Generic.SortedList`2+SortedListValueEnumerator[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at Microsoft.VisualStudio.Shell.ServiceProviderHierarchy.GetService(System.Type)
   at System.ComponentModel.Design.ServiceContainer.GetService(System.Type)
   at System.ComponentModel.Design.DesignerHost.GetService(System.Type)
   at System.ComponentModel.Design.DesignerHost+Site.System.IServiceProvider.GetService(System.Type)
   at System.Windows.Forms.Control.get_AmbientPropertiesService()
   at System.Windows.Forms.Control.get_BackColor()
   at System.Windows.Forms.Control.set_BackColor(System.Drawing.Color)
   at Multiplier.Heater.UpdateTemp(Boolean)
   at Multiplier.Heater.<.ctor>b__0()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

Это самая странная вещь, которую я столкнулся до сих пор. Помочь, чтобы быть прицепной.

5
задан Danpe 3 September 2011 в 15:16
поделиться