未处System.StackOverflowException 确保程序没有无限循环或无线递归
我想在form2点击一个按钮的时候form1显示form2隐藏,然后关闭form1的时候form2也同时关闭,而且窗体form1需要用到form2窗体中的client_Socket; server_Socket;,所以我在form1中声明了form2 的实例,可调试的时候出问题了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace howareyou
{
public delegate void childcolose();
public partial class Form2 : Form
{
public Socket server_Socket;
public Socket client_Socket;
private Form1 game_form = new Form1();
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
game_form.closefather += new childcolose(this.closing);
this.Hide();
game_form.Show();
Thread lisetn = new Thread(new ThreadStart(ListenNow)); //开启监听线程
lisetn.IsBackground = true; //设置后台线程isbackground属性为true,确保主线程关闭时,后台线程同时关闭
lisetn.Start();
}
void closing()
{