无法访问已释放的对象。 对象名:“WebBrowser”

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaokailele/article/details/48541441
if (webBrowser1 != null && !webBrowser1.IsDisposed)

无法访问释放对象!!!!!

10-16

以下是form1的代码:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnrnnamespace _20080517S2rnrn public partial class MainForm : Formrn rn From2 fa;rn public MainForm()rn rn InitializeComponent();rn fa = new From2();rn fa.MdiParent = this;rn fa.WindowState = FormWindowState.Maximized;rn fa.button1.Click += new EventHandler(button1_Click);rn rn rn rn void button1_Click(object sender, EventArgs e)rn rn MessageBox.Show(fa.Timu);rn fa.Close();rn rn rn rn rn private void 增加题目ToolStripMenuItem_Click(object sender, EventArgs e)rn rn fa.Show();rn rn rnrnrnrn下面是form2的代码:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnrnnamespace _20080517S2rnrn public partial class From2: Formrn rn public From2()rn rn InitializeComponent();rn rn public string Timurn rn get return this.textBox1.Text; rn rn public string XX1rn rn get return this.textBox2.Text; rn rn public string XX2 rn get return this.textBox3.Text; rn rn public string XX3 rn get return this.textBox4.Text; rn rn public string XX4 rn get return this.textBox5.Text; rn rnrn private void button1_Click(object sender, EventArgs e)rn rn MessageBox.Show(this.Timu);rn rn rn rnrnrnrn第一次点击”增加题目“时 form2 正常SHOW出来!rnrn输入完后 点FORM2的Button1关闭rnrn然后第二次点击“增加题目”的时候就会出现 “无法访问已释放的对象” 的错误rnrn为什么会这样 rnrn环境:VS2008 论坛

无法访问释放对象。\r\n对象名:“System.Net.Sockets.Socket”。

02-07

在数据表中共有5个IP段,分别是123.164.122.1// 123.164.122.2// 123.164.122.3// 123.164.122.4// 123.164.122.5 虚幻从数据库中取出这些IP并使用socket通信连接.rnrnrn在成功连接了一个IP后,马上socket关掉,循环连接第二个,依次........rnrn明明已经成功释放,但是程序却提示:"无法访问已释放的对象。\r\n对象名:“System.Net.Sockets.Socket”。"rnrn该如何解决,是不是要等待时间释放,谢谢,在线等rnrnrn代码如下:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnrnusing System.Data.SqlClient;rnusing System.Configuration;rnusing System.Net;rnusing System.Net.Sockets;rnusing System.Threading;rnusing Microsoft.Win32;rnrnrnnamespace CommandSendrnrn public partial class Form1 : Formrn rn public Form1()rn rn InitializeComponent();rn rn System.Net.Sockets.Socket su = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); rn System.Net.IPAddress addr = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);rn public string StrIp,StrState;rn //Thread t;rnrn #region 发送命令rn public void WaitData()rn rn tryrn rn rnrn string sql = " SELECT * FROM Ip ";rn DataTable dt = Conn.BindTable(sql);rn if (dt.Rows.Count != 0)rn rn for (int i = 0; i < dt.Rows.Count; i++)rn rn if (dt.Rows[i]["IP"].ToString().Replace("'", "''").Trim() != "")rn rn byte[] bytes = new byte[1024];rnrn System.Net.IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());rn System.Net.IPAddress[] ipAddress = ipHostInfo.AddressList;rn rn StrIp = dt.Rows[i]["IP"].ToString().Replace("'", "''").Trim();rn StrState = dt.Rows[i]["State"].ToString().Replace("'", "''").Trim();rnrn IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(StrIp), 9802);rn su.Connect(localEndPoint);rnrn su.Send(Encoding.Unicode.GetBytes(StrState.ToString().Replace("'", "''").Trim()));rnrn su.Receive(bytes);rn this.label1.Text = Encoding.Unicode.GetString(bytes).Replace("'", "''").Trim();rnrn //if (this.label1.Text == "OK")rn //rn su.Close();rn //rn rn rn rn rn rn rn catch (Exception ex)rn rn string a = ex.ToString();rn su.Close();rn rn finallyrn rn su.Close();rn rnrn rn #endregionrnrn #region 初始化rn private void Form1_Load(object sender, EventArgs e)rn rn WaitData();rn rn #endregionrn rn 论坛

没有更多推荐了,返回首页