Delegates, returning values to main form

i'm stuck and can't find solution. I'm a novice in C#...

I have two files in my project...this is just a simplified example, my real app is more complicated :)
1. Main FORM that has a textbox and a Button on it.
2. and annother file "CLASS" that has defined a function that generates random values (for example).

now... On a click of a button I create a thread that calls function form that class file like this.

Class1 delaj = new Class1();
Thread t = new Thread(new ThreadStart(delaj.GenerateNumbers));
t.Start();

...here is my problem. How can I pass generated value back to main form, each time that is generated, so that I can append generated value in my textbox? I know how to create event handler so that I can trigger an event each time that number is generated. I can't figure it out how to get that geneated value.
LVL 9
gruntarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Take a look at this article, it is close to your case. It passes strings, replace strings with numbers.

http://www.codeguru.com/Csharp/Csharp/cs_syntax/article.php/c5851/

Changes:

public delegate void DelegateNumber(int n);
...

public class MainForm : System.Windows.Forms.Form
{
    public DelegateNumber m_DelegateNumber;
    ...

    m_DelegateNumber = new DelegateNumber(this.AddNumber);
    ...

    private void AddNumber(int n)
    {
      // add number to textbox here
    }
}

Thread code (assuming that m_form is reference to the form):

int n = 5;   // some number

m_form.Invoke(m_form.m_DelegateNumber, new Object[] {n});

or:

m_form.BeginInvoke(m_form.m_DelegateNumber, new Object[] {n});
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
Why don't you create a static function so that you don't need an instantiated class to retrieve a random number?  It would be like String.Format, Array.Sort, etc.

Bob
0
gruntarAuthor Commented:
TheLearnedOne, can you give me an example for my case?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.