Darth Vader 0 Junior Poster in Training

I think I am missing out some logic when it comes to the backgroundworker.

For this scenario. I am using a loop in the backgroundworker.
Each loop I am calling an event that is writing values to a file.
After writing these values, I am increasing updateValue.

The problem is that the backgroundworker doesn´t get this updated updateValue for next looping.

However I have done a test with Sleep(5000) to see if the Messagebox will show the increased value. In this case it does.

I wonder why this is happening and what is the correct way to solve this problem.

private: Void backgroundWorker1_DoWork(Object^ sender, DoWorkEventArgs^ e)
        {
            for( int i = 0; i < 5; i++ )
            {
                //Thread.Sleep(5000); If using sleep the Messagebox will show correct updateValue, otherwise not.
                MessageBox.Show(updateValue.ToString());
                RF.t1 += gcnew t1DataEventHandler(this.t1);
            }
        }

        int updateValue = 0;
        private: Void t1(Object^ sender, t1DataEvent^ e)
        {
            //Write to file. (Takes about 1 second each time)
            updateValue = updateValue + 1;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.