I've written a threading program as a window form application in Visual Studio 2005.
It runs fine when run without debugging.
But when run with debugging it throws a cross thread exception.
I would like to have a solution for it.
Also i would like to know the difference between running an application with and without debug.
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;
namespace
thrd_sampl1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ThreadStart ts;
Thread th;
public static int i = 0;
public void add()
{
while (true)
{
i++;
// Thread.Sleep(3000);
Disp_tbx.Text = i.ToString();
}
}
private void start_btn_Click(object sender, EventArgs e)
{
ts =
new ThreadStart(add);
th =
new Thread(ts);
// Disp_tbx.Text = i.ToString();
th.Start();
}
private void abort_btn_Click(object sender, EventArgs e)
{
th.Abort();
// this.Close();
}
}
}