porkshopp
Active member
I have this Windows forms application that should run a very basic probability simulation based on deathchance and replicationchance. But my TextBox3 is not updating in realtime but updates once, when the entire species dies out. How do I get it to update in realtime?
C#:
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;
using System.Threading;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void Label3_Click(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
int Count;
bool success3 = int.TryParse(textBox4.Text, out Count);
if (success3)
{
Count = Convert.ToInt16(textBox4.Text);
}
else textBox3.Text = "Invalid Syntax!";
double rChance;
double dChance;
bool success = double.TryParse(textBox1.Text, out dChance);
bool success2 = double.TryParse(textBox2.Text, out rChance);
if (success && success2 && rChance <= 100 && rChance >= 0 && dChance >= 0 && dChance <= 100 && success3)
{
bool simulation = false;
while (!simulation)
{
textBox3.Text = Count.ToString();
Random rng = new Random();
int num = rng.Next(0, 101);
int num2 = rng.Next(0, 101);
if (num < rChance && Count != 0) Count++;
if(num2 < dChance && Count != 0) Count--;
if (Count == 0) simulation = true;
Thread.Sleep(1);
}
}
else textBox3.Text = "Invalid Syntax!";
}
private void TextBox4_TextChanged(object sender, EventArgs e)
{
}
}
}