当前位置:编程学习 > C#/ASP.NET >>

C# 状态栏控件 System.ArgumentOutOfRangeException

我的Winform程序中有个状态栏有4个计数的功能
但不知为什么就是更新ToolStripStatusLabel会报异常,我明明只是更新label为什么会报数组异常呢?异常具体内容为:
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
   在 System.Collections.ArrayList.get_Item(Int32 index)
   在 System.Windows.Forms.ToolStripItemCollection.get_Item(Int32 index)
   在 System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e)
   在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   在 System.Windows.Forms.Control.WmPaint(Message& m)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
   在 System.Windows.Forms.StatusStrip.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
AMBInterface
    程序集版本: 1.0.0.0
    Win32 版本: 1.0.0.0
    基本代码: file:///D:/Code/SMIS2013/trunk/20%E5%B7%A5%E7%A8%8B/20.40%E6%BA%90%E4%BB%A3%E7%A0%81/%E5%AE%89%E6%A3%80%E6%8E%A5%E5%8F%A3/AMBInterface/AMBInterface/bin/Debug/AMBInterface.exe
----------------------------------------
System.Windows.Forms
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
log4net
    程序集版本: 1.2.10.0
    Win32 版本: 1.2.10.0
    基本代码: file:///D:/Code/SMIS2013/trunk/20%E5%B7%A5%E7%A8%8B/20.40%E6%BA%90%E4%BB%A3%E7%A0%81/%E5%AE%89%E6%A3%80%E6%8E%A5%E5%8F%A3/AMBInterface/AMBInterface/bin/Debug/log4net.DLL
----------------------------------------
System.Configuration
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Web.Services
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Services/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
System.Data
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Transactions
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Microsoft.GeneratedCode
    程序集版本: 1.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Numerics
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
mscorlib.resources
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本: 4.0.0.0
    Win32 版本: 4.0.30319.17929 built by: FX45RTMREL
    基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如: 

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何未经处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。
--------------------编程问答-------------------- 你应该发 “计数的功能” 这段代码看看 --------------------编程问答--------------------
tsslLKSum.Text = _LKSum.ToString();
tsslLKHandle.Text = _LKHandle.ToString();
tsslXLSum.Text = _XLSum.ToString();
tsslXLHandle.Text = _XLHandle.ToString();

就是在一个线程里获取到数据后就计数,然后 赋值给text.出现这个问题以后,就状态栏变成红叉,异常点了继续后,程序还能正常运行
--------------------编程问答-------------------- omg,你在线程中不能直接操作用户界面的,要用invoke委托,知道不? --------------------编程问答-------------------- 这个我知道我加了 CheckForIllegalCrossThreadCalls = false;
这个问题不是经常出现的,貌似是程序运行后,我切换点了其他窗口,然后果断时间就会出现这个问题
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,