Starting two threads runs them in sequence and not at the same time
<p>I have a main thread which is controlling a windows form, upon pressing a button two threads are executed. One is used for recording information, the other is used for reading it. The idea behind putting these in threads is to enable the user to interact with the interface while they are executing.</p>

<p>Here is the creating of the two threads; </p>

<pre><code>Thread recordThread = new Thread(() =&gt; RecordData(data));
recordThread.Name = "record";
recordThread.Start();

Thread readThread = new Thread(() =&gt; ReadData(data));
readThread.Name = "read";
readThread.Start();
</code></pre>

<p>The <em>data</em> is simply a Data-object that stores the data that is recorded during the recording.</p>

<p>The problem that I am facing is that the first thread is executed fine, the second refuses to run until the first one completes. Putting a breakpoint in the second threads function, <em>ReadData</em> lets me know that it is only called after the first thread is done with all of its recording.</p>

<p>I have been trying to solve this for a few hours now and I can't get my head around why it would do this. Adding a;</p>

<pre><code>while(readThread.IsAlive) { }
</code></pre>

<p>right after the start will halt the execution of anything after that, and it's state is <em>Running</em>. But it will not go to the given method.</p>

<p>Any ideas?</p>

<p><strong>Edit</strong>:
The two functions that are called upon by the threads are;</p>

<pre><code>    private void RecordData(Data d)
    {
        int i = 0;
        while (i &lt; time * freq)
        {
            double[] data = daq.Read();
            d.AddData(data);
            i++;
        }
    }

    private void ReadData(Data d)
    {
        UpdateLabelDelegate updateData =
            new UpdateLabelDelegate(UpdateLabel);

        int i = 0;
        while (i &lt; time * freq)
        {
            double[] data = d.ReadLastData();
            this.Invoke(updateData, new object[] { data });
            i++;
        }
    }
</code></pre>

<p>The <em>data</em> object has locking in both the functions that are called upon; <em>ReadLastData and Read</em>.</p>

<p>Here are the methods in the <em>Data</em> object.</p>

<pre><code>    public void AddData(double[] data)
    {
        lock (this)
        {
            int i = 0;
            foreach (double d in data)
            {
                movementData[i].Add(d);
                i++;
            }
        }
    }

    public double[] ReadLastData()
    {
        double[] data = new double[channels];
        lock (this)
        {
            int i = 0;
            foreach (List&lt;double&gt; list in movementData)
            {
                data[i] = list[list.Count - 1];
            }
        }
        return data;
    }
</code></pre>
