Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3955418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:13:46+00:00 2026-05-20T02:13:46+00:00

I am trying to generate a random fruit and display it on GUI in

  • 0

I am trying to generate a random fruit and display it on GUI in a label. I am using this code to do it.

 partial class Form1 : Form
 {
    int MagicNumber = 0;
    List<string> NameList = new List<string>();
    Random r = new Random();

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        NameList.Add("Apples");
        NameList.Add("Pears");
        NameList.Add("Oranges");
        NameList.Add("Bananas");
        NameList.Add("Kiwi");

        for (int i = 0; i < 8; i++)
        {
            Thread t = new Thread(new ThreadStart(Display));
            t.Start();

            label1.Text = NameList[MagicNumber];
            Thread.Sleep(1000);
        }
   }

    private void Display()
    {
        MagicNumber = r.Next(5);
    }
}

The problem is the fact that in GUI i see only the last result of fruits choice and not how they are skipped from an iteration to other. I thought that this code will give me the possibility to see how fruits changes until the last was chosen , when i is 8.

Please if you have an idea why this code is not displaying how the fruits are chosen in label give me a hand !

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:13:47+00:00Added an answer on May 20, 2026 at 2:13 am

    Just call Application.DoEvents(); after assigning text to label – that will refresh UI.

    BTW I don’t understand why you are using threads to generate random numbers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate code coverage reports with EMMA using tests of which some
I am trying to generate random floats using nothing but bytes I get from
I'm trying to generate a random 64bit unsigned integer using boost random, but I'm
I am trying to figure out how to generate random from using /dev/random and
This is a Javascript / jQuery question: I'm trying to generate six unique random
I'm trying to generate random permutations of an 80-character fixed string in C. Much
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
I'm trying to generate some code at runtime where I put in some boiler-plate
I am trying to generate random data for my sql server database. Ive created
Hi I am trying to generate random numbers in MATLAB with a random MEAN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.