Slow dynamic button add/remove in C# - c#

I’am switching between buttons by adding/removing them dynamically. After 20 switches the whole application starts to be more and more slow.
It seem’s It is related to function Dispose(). When I use it the problem become worst. You can see how I used it in pasted code.
I’am using Visual Studio 2010 Express.
Any idea what I’am doing wrong?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Tracker
{
public partial class Tracker : Form
{
Button New_Trace = new Button();
Button Continue_Trace = new Button();
Button Save_Trace = new Button();
Button New_Point = new Button();
Button Exit_Trace = new Button();
public Tracker()
{
InitializeComponent();
Init_Menu1();
}
public void Init_Menu1()
{
New_Trace.Left = 20;
New_Trace.Top = 40;
New_Trace.Text = "New Trace";
this.New_Trace.Click += new System.EventHandler(this.New_Trace_Click);
this.Controls.Add(New_Trace);
Continue_Trace.Left = 100;
Continue_Trace.Top = 40;
Continue_Trace.Text = "Cont. Trace";
this.Continue_Trace.Click += new System.EventHandler(this.Continue_Trace_Click);
this.Controls.Add(Continue_Trace);
Save_Trace.Left = 180;
Save_Trace.Top = 40;
Save_Trace.Text = "Save Trace";
this.Save_Trace.Click += new System.EventHandler(this.Save_Trace_Click);
this.Controls.Add(Save_Trace);
}
public void Init_Menu2()
{
New_Point.Left = 20;
New_Point.Top = 40;
New_Point.Text = "New Point";
this.New_Point.Click += new System.EventHandler(this.New_Point_Click);
this.Controls.Add(New_Point);
Exit_Trace.Left = 180;
Exit_Trace.Top = 40;
Exit_Trace.Text = "Exit";
this.Exit_Trace.Click += new System.EventHandler(this.Exit_Trace_Click);
this.Controls.Add(Exit_Trace);
}
public void remove_Menu1()
{
if (this.Controls.Contains(New_Trace))
{
// this.New_Trace.Click -= new System.EventHandler(this.New_Trace_Click);
this.Controls.Remove(New_Trace);
//New_Trace.Dispose();
}
if (this.Controls.Contains(Continue_Trace))
{
// this.Continue_Trace.Click -= new System.EventHandler(this.Continue_Trace_Click);
this.Controls.Remove(Continue_Trace);
//Continue_Trace.Dispose();
}
if (this.Controls.Contains(Save_Trace))
{
// this.Save_Trace.Click -= new System.EventHandler(this.Save_Trace_Click);
this.Controls.Remove(Save_Trace);
//Save_Trace.Dispose();
}
}
public void remove_Menu2()
{
if (this.Controls.Contains(New_Point))
{
//this.New_Point.Click -= new System.EventHandler(this.New_Point_Click);
this.Controls.Remove(New_Point);
//New_Point.Dispose();
}
if (this.Controls.Contains(Exit_Trace))
{
//this.Exit_Trace.Click -= new System.EventHandler(this.Exit_Trace_Click);
this.Controls.Remove(Exit_Trace);
//Exit_Trace.Dispose();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void New_Trace_Click(object sender, EventArgs e)
{
remove_Menu1();
Init_Menu2();
}
private void Continue_Trace_Click(object sender, EventArgs e)
{
}
private void Save_Trace_Click(object sender, EventArgs e)
{
}
private void New_Point_Click(object sender, EventArgs e)
{
}
private void Exit_Trace_Click(object sender, EventArgs e)
{
remove_Menu2();
Init_Menu1();
}
}
}

Try changing visible of button to false/true instead of deleting and recreating it.
button.Visible = true; //set visible to visible
button.Visible = false; //set visible to invisible
button.Visible = !(button.Visible); //set visible to visible if button was invisible or to invisible, if button was Visible
Also In VS 2015 you have profiling tools, which can help you (but I'm not sure If they're in VS 2010 too)
Please, mark my answer as correct, if I helped you :D

Related

c# button click on new form takes long time to load

i have a button click to pop up a new form, and it is taking a while to load up. the following is my
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CashPOS
{
public partial class SubItems : Form
{
CashSales cashSalesForm;
List<string> itemList= new List<String>();
public SubItems()
{
InitializeComponent();
addItemToList();
getMainFormInfo();
}
private void getMainFormInfo()
{
cashSalesForm = new CashSales();
createItemBtn(itemList, subItemPanel, itemBtnClicked);
}
private void addItemToList()
{
itemList.Add("abc12");
itemList.Add("abc13");
itemList.Add("abc14");
itemList.Add("abc15");
itemList.Add("abc16");
itemList.Add("abc17");
itemList.Add("abc18");
itemList.Add("abc19");
itemList.Add("abc20");
itemList.Add("abc21");
itemList.Add("abc22");
itemList.Add("abc23");
itemList.Add("abc24");
itemList.Add("abc25");
itemList.Add("abc26");
itemList.Add("abc27");
itemList.Add("abc28");
itemList.Add("abc29");
itemList.Add("abc30");
itemList.Add("abc31");
itemList.Add("abc32");
itemList.Add("abc33");
itemList.Add("abc34");
itemList.Add("abc35");
itemList.Add("abc36");
itemList.Add("abc37");
itemList.Add("abc38");
itemList.Add("abc39");
}
protected void itemBtnClicked(object sender, EventArgs e)
{
float unitPrice = 0.0f;
Button btn = sender as Button;
string itemSelected = btn.Text;
}
public void createItemBtn(List<String> itemList, Control panel, EventHandler handler)
{
for (int i = 0; i < itemList.Count; i++)
{
Button newButton = new Button();
newButton.Width = 203;
newButton.Height = 132;
newButton.AutoSize = false;
newButton.Name = "newBtn" + i;
newButton.Text = itemList[i].ToString();
// btnList.Add(newButton);
panel.Controls.Add(newButton);
}
}
}
}
this is the form that open from the following button click event
protected void itemBtnClicked(object sender, EventArgs e)
{
Button btn = sender as Button;
string itemSelected = btn.Text;
SubItems sub = new SubItems();
sub.Show();
}
i am not sure if the createItemBtn is delaying it by alot, because when I remove this function, it would open the form instantly, but with this function, it takes around 1.5 second to open the form. Is there a better way to reduce the time for this?

How do you scroll down scroll bar on windows form panel top to bottom automatically on form load?

I am making pdf file opener on windows form using c#. I want to make windows form to grap pdf file name from specific folder to combobox and make combobox select next content in every x mins. But due to axAcroPDF1 using settings from adobe reader, I can't make single page fit full screen without keeping ratio which leaves huge unfilled area left and right without keeping the original aspect ratio. Since I can't get rid of it using adobe reader, I have to use fit to width but this make the page too big for reader and I can't view entire content without scroll down.
I've tried everything I can think of but I can't make it work.
private void Form1_Load(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
DirectoryInfo test = new DirectoryInfo(#"\c:\temp\");
FileInfo[] Files = test.GetFiles("*.pdf"); //Getting Text files
var fileNames = Files.Select(f => Path.GetFileNameWithoutExtension(f.Name)).ToList();
comboBox1.DataSource = fileNames;
timerset();
}
private void panel1_ControlAdded(object sender, ControlEventArgs e)
{
}
public void axSetting()
{
axAcroPDF1.setShowToolbar(false);
axAcroPDF1.setView("FitH");
axAcroPDF1.setPageMode("none");
axAcroPDF1.setShowScrollbars(false);
axAcroPDF1.setLayoutMode("SinglePage");
axAcroPDF1.Show();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axAcroPDF1.LoadFile(#"c:\temp\ + comboBox1.Text + ".pdf");
axAcroPDF1.src = #"c:\temp\" + comboBox1.Text + ".pdf";
axSetting();
}
public void comboBoxSelect()
{
if (comboBox1.SelectedIndex < (comboBox1.Items.Count - 1))
{
comboBox1.SelectedIndex += 1;
}
else
{
comboBox1.SelectedIndex = 0;
DirectoryInfo test = new DirectoryInfo(#"c:\temp\");
FileInfo[] Files = test.GetFiles("*.pdf");
var fileNames = Files.Select(f => Path.GetFileNameWithoutExtension(f.Name)).ToList();
comboBox1.DataSource = fileNames;
}
}
public void timerset()
{
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 10000; // in miliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
comboBoxSelect();
}
How do I make the autoscroll on panel to scroll from top to bottom at load of each pdf file?
Try it now it works:
I changed these to be true:AxAcroPDF1.setShowToolbar(True) axAcroPDF1.setShowScrollbars(True); and I added comboBox1.SelectedIndex = 1; and axAcroPDF1.AutoScrollOffset = new Point(axAcroPDF1.AutoScrollOffset.X, 10);
axAcroPDF1.AutoScrollOffset = new Point(axAcroPDF1.AutoScrollOffset.Y, 10);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
DirectoryInfo test = new DirectoryInfo(#"c:\temp\");
FileInfo[] Files = test.GetFiles("*.pdf"); //Getting Text files
var fileNames = Files.Select(f => Path.GetFileNameWithoutExtension(f.Name)).ToList();
comboBox1.DataSource = fileNames;
comboBox1.SelectedIndex = 1;
axAcroPDF1.AutoScrollOffset = new Point(axAcroPDF1.AutoScrollOffset.X, 10);
axAcroPDF1.AutoScrollOffset = new Point(axAcroPDF1.AutoScrollOffset.Y, 10);
timerset();
}
private void panel1_ControlAdded(object sender, ControlEventArgs e)
{
}
public void axSetting()
{
axAcroPDF1.setShowToolbar(true);
axAcroPDF1.setView("FitH");
axAcroPDF1.setPageMode("none");
axAcroPDF1.setShowScrollbars(true);
axAcroPDF1.setLayoutMode("SinglePage");
axAcroPDF1.Show();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axAcroPDF1.LoadFile(#"c:\temp\" + comboBox1.Text + ".pdf");
axAcroPDF1.src = #"c:\temp\" + comboBox1.Text + ".pdf";
axSetting();
}
public void comboBoxSelect()
{
if (comboBox1.SelectedIndex < (comboBox1.Items.Count - 1))
{
comboBox1.SelectedIndex += 1;
}
else
{
comboBox1.SelectedIndex = 0;
DirectoryInfo test = new DirectoryInfo(#"c:\temp\");
FileInfo[] Files = test.GetFiles("*.pdf");
var fileNames = Files.Select(f => Path.GetFileNameWithoutExtension(f.Name)).ToList();
comboBox1.DataSource = fileNames;
}
}
public void timerset()
{
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 10000; // in miliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
comboBoxSelect();
}
}
}
I usually set the AutoScrollPosition like this.
You need to have this code in the Shown() event of a Form (not the Load()).
[ScrollableContainer].AutoScrollPosition =
new Point(0, [ChildControl].Height - [ScrollableContainer].Height);
The Size of [ChildControl] is of course greater than its [ScrollableContainer]'s.
It could also simply be:
[ScrollableContainer].AutoScrollPosition = new Point(0, [ChildControl].Height);

Button "clear" on a TextBox line appears only once

I managed to get a clear button on a TextBox line with little code. This deletes the corresponding line and itself when clicking. But the button appears only once. It should be generated with each click on each additional line. Can someone help me there? Many Thanks.
Is WinForm VS2010 C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Daten_zu_TextBox_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Button btn1 = new Button();
btn1.Name = "btn";
btn1.Click += new EventHandler(btn1_Click);
btn1.Size = new Size(18, 18);
btn1.Text = "X";
btn1.ForeColor = Color.Red;
textBox1.Controls.Add(btn1);
string sent = ("\t" + "Testline1");
textBox1.AppendText(sent);
textBox1.AppendText(Environment.NewLine);
}
void btn1_Click(object sender, EventArgs e)
{
textBox1.Controls.Clear();
textBox1.Text = textBox1.Text.Remove(1, textBox1.Lines[0].Length + 0 );
textBox1.Text = textBox1.Text.Remove(0, textBox1.Lines[0].Length + 0);
}
}
}
private int ButtonCount2 = 0;
private int Btn2Y = 18;
private void button2_Click(object sender, EventArgs e)
{
Button btn2 = new Button();
btn2.Name = "btn2" + ButtonCount2;
btn2.Click += new EventHandler(btn2_Click);
btn2.Size = new Size(18, 18);
btn2.Location = new Point(1, Btn2Y * ButtonCount2);
ButtonCount2++;
btn2.Text = "X";
btn2.ForeColor = Color.Red;
textBox2.Controls.Add(btn2);
string sent = ("\t" + "Testline" + ButtonCount2);
textBox2.AppendText(sent);
textBox2.AppendText(Environment.NewLine);
}
void btn2_Click(object sender, EventArgs e)
{
var bt2 = sender as Button;
var bt2Id = textBox2.Controls.IndexOf(bt2);
textBox2.Controls.Remove(bt2);
var lines = textBox2.Text.Replace("\r\n", "\n").Split('\n').ToList();
lines.RemoveAt(bt2Id);
textBox2.Text = string.Join("\r\n", lines);
foreach (Button btn2 in textBox2.Controls)
{
var Id2 = int.Parse(btn2.Name.Replace("btn2", ""));
if (Id2 > bt2Id)
{
var b2 = textBox2.Controls.Find(btn2.Name, false)[0];
var loc2 = btn2.Location;
b2.Location = new Point(loc2.X, loc2.Y - Btn2Y);
}
}
ButtonCount2--;
}
The second button looks like this.
You're putting all the X buttons on the same place, on top of textbox. Implement some logic that increases Y location of your button. That can be something like this:
//... your code here ...
btn1.ForeColor = Color.Red;
//increase Y
// for each control that is inside of textBox,
// lower your newly created button by count * 18
// so that btn1.Top will be 0, 18, 36 etc...
btn1.Top = textBox1.Controls.Count * 18;
textBox1.Controls.Add(btn1);
also, as WPFUser noticed, on click on X button, you're removing all the X buttons. I'm guessing you should remove last, bottom one
EDIT 2. Each button should remove its corresponding line, like this (didn't test it :))
void btn1_Click(object sender, EventArgs e)
{
//remove right line
text1.Text = text1.Lines[text1.Controls.IndexOf((Control)sender)].Remove(0);
//remove button
text1.Controls.Remove(text1.Controls.OfType<Button>().Last());
}
#jadolo ,Your code is correct ,It add new button every time but every button will located at same location so those all button will not visible to you, Add assign location property of button like this,so all button are displayed correctly.
Form1.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
int i = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
void btn1_Click(object sender, EventArgs e)
{
textBox1.Controls.Clear();
textBox1.Text = textBox1.Text.Remove(1, textBox1.Lines[0].Length + 0);
textBox1.Text = textBox1.Text.Remove(0, textBox1.Lines[0].Length + 0);
}
private void button1_Click_1(object sender, EventArgs e)
{
Button btn1 = new Button();
btn1.Name = "btn"+i++;
btn1.Click += new EventHandler(button1_Click_1);
btn1.Size = new Size(18,18 );
btn1.Text = "X";
btn1.Location = new Point(0, i);
i += 18;
btn1.ForeColor = Color.Red;
this.textBox1.Controls.Add(btn1);
string sent = ("\t" + "Testline1");
textBox1.AppendText(sent);
textBox1.AppendText(Environment.NewLine);
}
}
}
Design :
Output :
I hope this will help you.
Below is tested working codes. The button will coincide with text for the textbox font size being the default 8.
private int ButtonCount = 0;
private int BtnY = 13;
private void button1_Click(object sender, EventArgs e)
{
Button btn1 = new Button();
btn1.Name = "btn" + ButtonCount;
btn1.Click += new EventHandler(btn1_Click);
btn1.Size = new Size(18, 18);
btn1.Location = new Point(1, BtnY * ButtonCount);
btn1.Tag = ButtonCount; // the last edit
ButtonCount++;
btn1.Text = "X";
btn1.ForeColor = Color.Red;
textBox1.Controls.Add(btn1);
string sent = ("\t" + "Testline" + ButtonCount);
textBox1.AppendText(sent);
textBox1.AppendText(Environment.NewLine);
}
void btn1_Click(object sender, EventArgs e)
{
var bt = sender as Button;
var btId = textBox1.Controls.IndexOf(bt);
textBox1.Controls.Remove(bt);
var lines = textBox1.Text.Replace("\r\n", "\n").Split('\n').ToList();
lines.RemoveAt(btId);
textBox1.Text = string.Join("\r\n", lines);
foreach (Button btn in textBox1.Controls)
{
//var Id = int.Parse(btn.Name.Replace("btn", "")); // the last edit
var Id = (int)btn.Tag; // the last edit
if (Id > btId)
{
var b = textBox1.Controls.Find(btn.Name, false)[0];
var loc = btn.Location;
b.Location = new Point(loc.X, loc.Y - BtnY);
}
}
ButtonCount--;
}

C# remove dynamic created button

I am facing an issue over here. I want to remove the dynamic created button by press the X button.
The function will be user press X button, then press the button he/she want to delete, the button will be remove.
For now my program is able to create a new button but I do not know how to delete it, here is my coding, please help me , thanks very much!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class graphtest : Form
{
public graphtest()
{
InitializeComponent();
}
private Point Origin_Cursor;
private Point Origin_Control;
private bool BtnDragging = false;
private void button1_Click(object sender, EventArgs e)
{
var b = new Button();
b.Width = 54;
b.Height = 58;
b.Image = Image.FromFile(#"C:\Users\prod01\Desktop\Mote.png");
b.Text = "";
b.Name = "button";
//b.Click += new EventHandler(b_Click);
b.MouseUp += (s, e2) => { this.BtnDragging = false; };
b.MouseDown += new MouseEventHandler(this.b_MouseDown);
b.MouseMove += new MouseEventHandler(this.b_MouseMove);
this.Controls.Add(b);
}
private void b_MouseDown(object sender, MouseEventArgs e)
{
Button ct = sender as Button;
ct.Capture = true;
this.Origin_Cursor = System.Windows.Forms.Cursor.Position;
this.Origin_Control = ct.Location;
this.BtnDragging = true;
}
private void b_MouseMove(object sender, MouseEventArgs e)
{
if (this.BtnDragging)
{
Button ct = sender as Button;
ct.Left = this.Origin_Control.X - (this.Origin_Cursor.X - Cursor.Position.X);
ct.Top = this.Origin_Control.Y - (this.Origin_Cursor.Y - Cursor.Position.Y);
}
}
private void graphtest_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
for (int ix = this.Controls.Count - 1; ix >= 0; ix--)
{
if (this.Controls[ix] is Button) this.Controls[ix].Dispose();
}
}
}
}
Here is how you can do that
//a list where you save all the buttons created
List<Button> buttonsAdded = new List<Button>();
private void button2_Click(object sender, EventArgs e)
{
Button myText = new Button();
myText.Tag = counter;
myText.Location = new Point(x2,y2);
myText.Text = Convert.ToString(textBox3.Text);
this.Controls.Add(myText);
//add reference of the button to the list
buttonsAdded.Insert(0, myText);
}
//atach this to a button removing the other buttons
private void removingButton_Click(object sender, EventArgs e)
{
if (buttonsAdded.Count > 0)
{
Button buttonToRemove = buttonsAdded[0];
buttonsAdded.Remove(buttonToRemove);
this.Controls.Remove(buttonToRemove);
}
}
Ref :- how to delete a button run time?

Application is not responding

What the application should do
This application should take the input of time (seconds, minutes and hours) and shutdown the computer after that time. It should also update the text box with how long left until the computer has shut down.
What the application actually does
I had an issue that I 'fixed' where the called ac across threads weren't safe, so I fixed it and I don't get that error now. However, the updateThread doesn't update and print the time left; and the text box doesn't get "test" appended to it. The UI also becomes Not Responding. Any help would be much appreciated.
Also, if you see anything else that could be done better, please comment and explain. Thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ShutdownPC
{
public partial class Form1 : Form
{
int inputHours;
int inputMinutes;
int inputSeconds;
Thread sleepingThread;
Thread updatingThread;
NotifyIcon shutdownPCIcon;
Icon defaultIcon;
public Form1()
{
InitializeComponent();
defaultIcon = new Icon("defaultIcon.ico");
shutdownPCIcon = new NotifyIcon();
shutdownPCIcon.Icon = defaultIcon;
shutdownPCIcon.Visible = true;
MenuItem progNameMenuItem = new MenuItem("ShutdownPC by Conor");
MenuItem breakMenuItem = new MenuItem("-");
MenuItem quitMenuItem = new MenuItem("Quit");
ContextMenu contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(progNameMenuItem);
contextMenu.MenuItems.Add(breakMenuItem);
contextMenu.MenuItems.Add(quitMenuItem);
shutdownPCIcon.ContextMenu = contextMenu;
shutdownPCIcon.Text = "ShutdownPC";
quitMenuItem.Click += QuitMenuItem_Click;
}
private void QuitMenuItem_Click(object sender, EventArgs e)
{
shutdownPCIcon.Dispose();
sleepingThread.Abort();
updatingThread.Abort();
this.Close();
}
public void sleepThread()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(sleepThread));
}
else {
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
button1.Enabled = false;
int totalMilliseconds = ((inputHours * 3600) + (inputMinutes * 60) + inputSeconds) * 1000;
Thread.Sleep(totalMilliseconds);
//Process.Start("shutdown", "/s /t 0");
richTextBox1.AppendText(String.Format("test"));
}
}
public void updateThread()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(updateThread));
}
else {
int totalSeconds = (inputHours * 3600) + (inputMinutes * 60) + inputSeconds;
while (totalSeconds > 0)
{
TimeSpan time = TimeSpan.FromSeconds(totalSeconds);
string timeOutput = time.ToString(#"hh\:mm\:ss");
richTextBox1.AppendText(String.Format(timeOutput));
Thread.Sleep(1000);
richTextBox1.Clear();
totalSeconds--;
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
inputHours = Convert.ToInt32(textBox1.Text);
inputHours = int.Parse(textBox1.Text);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
inputMinutes = Convert.ToInt32(textBox2.Text);
inputMinutes = int.Parse(textBox2.Text);
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
inputSeconds = Convert.ToInt32(textBox3.Text);
inputSeconds = int.Parse(textBox3.Text);
}
private void button1_Click(object sender, EventArgs e)
{
updatingThread = new Thread(new ThreadStart(updateThread));
updatingThread.Start();
sleepingThread = new Thread(new ThreadStart(sleepThread));
sleepingThread.Start();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Using Invoke in the beginning of method that runs in separate thread is bad idea, because all code runs in GUI thread and lock it.
You should Invoke only GUI updating code!!!

Categories