0

I need to display the members of an array one-by-one into a label using thread. The thread needs to change the content every second. How could I achieve this?

My code is as follows:

private void Form1_Load(object sender, EventArgs e)
{
    string[] heartRate = new String[] {"153","155","157","155","153","154"};
    myThread display = new myThread();

    display.hr =  Array.ConvertAll(heartRate, num => Int32.Parse(num));

    Thread threadHeartRate = new Thread(display.threadHeartrate);   
}

public class myThread
{
    private int[] _hr;
    internal int[] hr  {get { return _hr; } set { _hr = value; } }
    public void threadHeartrate()
    {
        for (int i = 0; i < _hr.Length; i++)
        {

        }
    }
}

The array I need to print is heartRate.

René Vogt
  • 43,056
  • 14
  • 77
  • 99
DazedNConfused
  • 189
  • 2
  • 13
  • 1
    http://stackoverflow.com/questions/2172467/set-value-of-label-with-c-sharp-cross-threading – CathalMF Apr 01 '16 at 13:03
  • 3
    Do you really need a thread (as an exercise or something)? Otherwise I would prefer a simple [Timer](https://msdn.microsoft.com/en-us/library/system.windows.forms.timer%28v=vs.110%29.aspx) – René Vogt Apr 01 '16 at 13:03
  • This is a WinForms application? Please tag your post accordingly. – Wicher Visser Apr 01 '16 at 13:03
  • @DanielA.White I'm not sure if this dupehammer is the best help. This thread is full of very outdated and verbose code, while OP would have probably best been helped with a simple [`Progress´](https://msdn.microsoft.com/en-us/library/hh193692%28v=vs.110%29.aspx). – René Vogt Apr 01 '16 at 13:13
  • yes, I need to use thread. It is an exercise on multithreaded programming. – DazedNConfused Apr 01 '16 at 13:16

0 Answers0