C
C#7mo ago
Monkey

Console app working with Windows Form app

Im trying to figure out how I can display my console output on a windows form I want to be able to display a variable everytime it gets updated However my current version only displays the variable after the loop has finished Is there any way around this or do I have to wait for the loop to finish
No description
No description
No description
2 Replies
leowest
leowest7mo ago
if the purpose is just to see what its printing you could use Debug.WriteLine instead and it will be output to the Output window of visual studio Otherwise u need to pinvoke to add the console https://stackoverflow.com/a/4363184/450121 the problem here is that Thread.Sleep locks the ui that is not how u want to do it
private async void Form1_Load(object sender, EventArgs e)
{
for (var i = 0; i < 11; i++)
{
label1.Invoke((MethodInvoker)delegate
{
label1.Text = $"{i}";
});
await Task.Delay(1000);
}
}
private async void Form1_Load(object sender, EventArgs e)
{
for (var i = 0; i < 11; i++)
{
label1.Invoke((MethodInvoker)delegate
{
label1.Text = $"{i}";
});
await Task.Delay(1000);
}
}
jcotton42
jcotton427mo ago
delegate :Skull:
Want results from more Discord servers?
Add your server