help
Root Question Message
for(;;)
loop and I'm new to csharp. Any explanation??namespace csNotes
{
public partial class Form1 : Form
{
public Form1()
{
ChangeRGB();
InitializeComponent();
}
void Sleep(double ms)
{
Thread.Sleep((int)(ms * 1000));
}
void ChangeRGB()
{
for(; ;)
{
Sleep(0.1);
// Change RGB
int c1 = new Random()
.Next(0, 255);
int c2 = new Random()
.Next(0, 255);
int c3 = new Random()
.Next(0, 255);
BackColor = Color.FromArgb(c1, c2, c3);
};
}
private void ClearButton_Click(object sender, EventArgs e)
{
// Clear the text box
inputBox.Clear();
}
}
}
Sleep
which blocks the main threadSleep(0.1);
for await Task.Delay(100);
async
modifier to the ChangeRGB
methodawait
keyword it can make a continuation (basically puts a bookmark in and closes the book) and then works on other code until whatever task is completedTask
object or an async
method (which compiles to return a Task
), so at a guess then C# stores a reference to that task and lets it run in the background (or shares processor time with it) while prioritising the rest of the program. Then once the task claims it's completed (or errored) then C# goes back and continues the ChangeRGB
method with the completed taskasync
would be where you'd spend the time chopping vegetables haha