I am trying to go off and collect data on a regular basis, which can take time, then once I have collated it all, use it in the GUI thread. The data can change - sometimes only 1 message, sometimes several.
If I use a simple example and pass a string in to RunWorkerAsync() then change the string by setting e.Result in the DoWork function, RunWorkerCompleted gets called (and has the new string in e.Result).
If I init an array as empty and pass this to RunWorkerAsync, then populate this array, changing its size with Array.Resize() and pass this result back as e.Result, then RunWorkerCompleted never fires.
What am I doing wrong?
Code example:
Expand|Select|Wrap|Line Numbers
- void main()
- {
- string[][] test = new string[0][];
- bgw.RunWorkerAsync(test)
- }
- void DoWork(object state, DoWorkEventArgs e)
- {
- string[][] test = e.Argument as string[][];
- Array.Resize(ref test,2);
- Array.Resize(ref test[0],2);
- Array.Resize(ref test[1],2);
- test[0][0] = "first feed, first message";
- test[0][1] = "first feed, second message";
- test[1][0] = "second feed, first message";
- test[1][1] = "second feed, second message";
- e.Result = test;
- }
- void RunWorkerCompleted(object state, RunWorkerCompletedEventArgs e)
- {
- //this never fires at all!!
- string[][] test = e.Result as string[][];
- textBox1.Text = test[0][0];
- }
All help gratefully received.