122
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
上一篇:
關於Webm格式的問題
下一篇:
Microsoft賬戶人脈和outlook帳戶人脈的關係能不能解釋一下
你的設備已過期,並缺少重要的安全和質量更新,因此存在風險。讓我們帶你重回正軌,這樣
Microsoft store 無法聯網,顯示Microsoft Store需要聯網,你似乎沒有聯網
設備以遷移 由於僅部分匹配或匹配不明確,因此無法遷移設備
由於在創建轉儲期間出錯,創建轉儲文件失敗。
發生臨時 DNS 錯誤
應用商店,在我們這邊發生問題,無法使你登陸,錯誤代碼: 0xD000000D
照相機不可用,錯誤代碼:0xA00F4244(0xC00DABE0)
應用商店打開異常提示“清單中指定了未知的布局”
自定義掃描Windows defender裏麵的設備性能和運行狀況 黃色感歎號問題
windows預口體驗成員內口版本遇到問題需要重啟
熱門內容
windows10 點開此電腦後,有兩個顯示硬盤盤符的目錄是怎麼回事?
windows 10 專業版無法下載中文語言包
KB4056892
win10不能共享文件夾
在Surfacebook上用Windows to go 1703版本,更新後重啟藍屏,無法進入係統
windows10 1709版本更新失敗,錯誤0x8007001f
microdoft visual c++ 2015 redistributable
WIN10 Insider Preview 17025更新失敗,錯誤代碼0x80096004
計算機管理服務 出現一個內部錯誤(INVALID
關於控製麵板中的安全和維護內提示Windows defender 防病毒已關閉的問題