阅读122 返回首页    go windows


C#程序ListBox崩溃问题

VS2012写的,Windows日志中的程序异常信息如下:

                         
//--------------------------------------------------异常信息----------------------------------------------------//

日志名称:          Application
来源:            .NET Runtime
日期:            2017/8/16 17:45:06
事件 ID:         1026
任务类别:          无
级别:            错误
关键字:           经典
用户:            暂缺
计算机:           CMP1-PC
描述:
应用程序: CMP.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。

异常信息: System.NullReferenceException
堆栈:

在 System.Windows.Forms.ListBox+ItemArray.GetItem(Int32, Int32)

在 System.Windows.Forms.ListBox+ObjectCollection.RemoveAt(Int32)

在 CMP.EPD.UpdateEPDCommMessage(System.String)

在 CMP.EPD.AddEPDCommMessage(System.String)

在 CMP.EPD.Client_OnRead(System.Net.Sockets.Socket, System.String)

在 CMP.EPD_client.OnDataReceived(System.IAsyncResult)

在 System.Net.LazyAsyncResult.Complete(IntPtr)

在 System.Net.ContextAwareResult.CompleteCallback(System.Object)

在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

在 System.Net.ContextAwareResult.Complete(IntPtr)

在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)

在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

事件 Xml:
<Event xmlns="https://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2017-08-16T09:45:06.000000000Z" />
    <EventRecordID>27800</EventRecordID>
    <Channel>Application</Channel>
    <Computer>CMP1-PC</Computer>
    <Security />
  </System>
  <EventData>
    <Data>
应用程序: CMP.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.NullReferenceException
堆栈:

在 System.Windows.Forms.ListBox+ItemArray.GetItem(Int32, Int32)

在 System.Windows.Forms.ListBox+ObjectCollection.RemoveAt(Int32)

在 CMP.EPD.UpdateEPDCommMessage(System.String)

在 CMP.EPD.AddEPDCommMessage(System.String)

在 CMP.EPD.Client_OnRead(System.Net.Sockets.Socket, System.String)

在 CMP.EPD_client.OnDataReceived(System.IAsyncResult)

在 System.Net.LazyAsyncResult.Complete(IntPtr)

在 System.Net.ContextAwareResult.CompleteCallback(System.Object)

在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

在 System.Net.ContextAwareResult.Complete(IntPtr)
   在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)

在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

    </Data>
  </EventData>
</Event>

//--------------------------------------------------异常信息----------------------------------------------------//

相关代码段如下,就是超过两百条之后移除第一条,根据高度计算显示最新的Listbox条目。

private void UpdateEPDCommMessage(string msg)
        {
            while (lbx_EPD_Comm.Items.Count > 200)
                lbx_EPD_Comm.Items.RemoveAt(0);
            lbx_EPD_Comm.Items.Add(msg);
            if (lbx_EPD_Comm.Items.Count >= (lbx_EPD_Comm.Height / lbx_EPD_Comm.ItemHeight))
            {
                lbx_EPD_Comm.TopIndex = lbx_EPD_Comm.Items.Count - (int)(lbx_EPD_Comm.Height / lbx_EPD_Comm.ItemHeight) + 1;
            }
        }

请大家给看看,是哪出的问题。谢谢



最后更新:2017-08-18 17:02:29

  上一篇:go 关于Webm格式的问题
  下一篇:go Microsoft账户人脉和outlook帐户人脉的关系能不能解释一下