Visual Studio多表格关闭并重新打开
嗨,我真的是UI应用程序的新手 删除代码。
namespace UDP_TEST_2
{
public partial class Form1 : Form
{
double x;
UdpClient Client = new UdpClient(5000);
void recv(IAsyncResult res)
{
IPEndPoint RemoteIP = new IPEndPoint(IPAddress.Any, 5000);
byte[] received = Client.EndReceive(res, ref RemoteIP);
data = Encoding.UTF8.GetString(received);
Client.BeginReceive(new AsyncCallback(recv), null);
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Tick += timer1_Tick;
timer1.Interval = 001;
try
{
Client.BeginReceive(new AsyncCallback(recv), null);
}
catch (Exception ex)
{
richTextBox1.Text += ex.Message.ToString();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//reading all bytes ETC
}
}
}
该代码在单个表单时起作用,但是自从我创建第二个表单以来,它将其称为f.showdialog(); 第一次操作很棒 的表单的代码
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.ShowDialog();
}
打开读取零件错误 我退出第二屏幕时打印了错误
hi i'm really new to UI applications and i'm trying to make a simple udp reader but everytime i close the program i have an error
stripped down code ..
namespace UDP_TEST_2
{
public partial class Form1 : Form
{
double x;
UdpClient Client = new UdpClient(5000);
void recv(IAsyncResult res)
{
IPEndPoint RemoteIP = new IPEndPoint(IPAddress.Any, 5000);
byte[] received = Client.EndReceive(res, ref RemoteIP);
data = Encoding.UTF8.GetString(received);
Client.BeginReceive(new AsyncCallback(recv), null);
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Tick += timer1_Tick;
timer1.Interval = 001;
try
{
Client.BeginReceive(new AsyncCallback(recv), null);
}
catch (Exception ex)
{
richTextBox1.Text += ex.Message.ToString();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//reading all bytes ETC
}
}
}
the code works when its a single form but ever since i created a second form and call this one with f.showdialog();
first time it opes great but when i close it and reopen it with the button i get this error
code of the form that opens the read part
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.ShowDialog();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关闭并处置
udpclient
。为此,您必须覆盖表格的distose
方法:根据
Close and Dispose the
UdpClient
. To do this you must override the form'sDispose
method:According to UdpClient.Close Method / Remarks: