閱讀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帳戶人脈的關係能不能解釋一下