how to generate multiple form under a running thread ..

Apr 1 2009 1:19 AM
HELLO in my project i want to create new runtime form every time user clicks on button1.i have to open form under a running thread.....this is my code.. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using System.Net; using System.Net.Sockets; using System.IO; namespace testthread { public partial class Form1 : Form { IPEndPoint receivept; delegate void settextcallback(string text); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(test)); t.IsBackground.CompareTo(true); t.Start(); CheckForIllegalCrossThreadCalls = false; } private void button1_Click(object sender, EventArgs e) { UdpClient send = new UdpClient(); IPEndPoint sendpt = new IPEndPoint(IPAddress.Parse("192.168.0.4"), 1080); byte[] data = System.Text.Encoding.UTF8.GetBytes("hello"); send.Send(data, data.Length, sendpt); send.Close(); } public void test() { UdpClient receive = new UdpClient(1080); do { try { byte[] data = receive.Receive(ref receivept); string text = System.Text.Encoding.UTF8.GetString(data); if (text.Contains("hello")) { data d = new data(); d.open("abhi"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } while (true); } class data { public data() { } public void open(string text) { Form f = new Form(); f.Show(); Application.Run(f); } } } } Thanks..