【发布时间】:2009-05-16 19:51:42
【问题描述】:
好吧,伙计们,我的代码中出现了这个以前没有出现过的突然问题..
public void StartUdpListener(Object state)
{
/* sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock1.Bind(receiveEndPoint);
EndPoint ep = (EndPoint)receiveEndPoint;*/
recv = sock1.ReceiveFrom(receivedNotification, ref ep);
notificationReceived = Encoding.ASCII.GetString(receivedNotification, 0, recv);
//sock1.Close();
if (listBox1.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate { listBox = new StringBuilder(this.listBox1.Text); });
}
listBox.AppendLine(notificationReceived);
if (listBox1.InvokeRequired)
{
pos = listBox1.FindString(notificationReceived);
if (pos >= 0)
{
}
else
{
this.Invoke((MethodInvoker)delegate { this.listBox1.Items.Add(listBox.ToString()); });
}
}
}
我收到一个 ObjectDisposedException ,说明以下行:
this.Invoke((MethodInvoker)delegate { listBox = new StringBuilder(this.listBox1.Text); });
无法执行,因为 listBox1 已被释放。这怎么可能?有什么需要做的吗?
【问题讨论】:
-
请编辑您的问题并输入一些适当的标签,并不是每个人都熟悉您之前提到的问题。
-
@micro:它在 c# 中。 @duckflip:我的整个程序非常大,可以在这里展示。能不能具体告诉我你没看懂的地方,以便我提供必要的相关代码。
标签: c# objectdisposedexception