3
Good afternoon, I’m doing a little school work to learn how to control radio Buttons with a switch in winforms
public Form1()
{
InitializeComponent();
Form1.CheckForIllegalCrossThreadCalls = false;
Thread th = new Thread(() =>
{
while (true)
{
RadioButton btn = this.tabPage1.Controls.OfType<RadioButton>().Where(x => x.Checked).FirstOrDefault();
if (btn != null && btn.Checked)
{
switch (btn.Name)
{
case "radioButton1":
MessageBox.Show("Ronaldo");
pictureBox1.Visible = true;
lblNome1.Visible = true;
lblPos1.Visible = true;
break;
case "radioButton2":
MessageBox.Show("Messi");
pictureBox2.Visible = true;
lblNome2.Visible = true;
lblPos2.Visible = true;
break;
}
}
}
});
th.Start();
}
There are no syntax errors only visibles are enabled only if there is a messagebox however this one like this within an infinite cycle of challenge, will always appear and to my knowledge has no way to stop
I thank those who can help me to solve this problem or who tried.
What is the need to use an infinite loop thread for these validations?
– Pedro Paulo
To not have to click a button to perform the switch action, it’s the only way I know so far so the code is always running as if it were live
– Pona
In addition to what @Pedropaulo has already said, are sure you need the
switch
this is also probably a mistake. It seems to be wanting to use all possible tools, even if they are inadequate. Almost all use ofthread
that I’ve seen is wrong, it’s unlikely that your case is right. Tip, only use what you dominate, if you don’t dominate, don’t use, or dominate before using.– Maniero
The exercise was given by my teacher, control rdb with a switch, I just joined the thread to not have to click a button, I don’t even know to use threads, true, but that’s how I saw online, and no, I didn’t domino c# but I liked to dominate and so I’m learning
– Pona