473,382 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

BackgroundWorker not triggering RunWorkerCompleted if Argument (array) changes size

1
Hi,

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
  1. void main()
  2. {
  3.   string[][] test = new string[0][];
  4.   bgw.RunWorkerAsync(test)
  5. }
  6.  
  7. void DoWork(object state, DoWorkEventArgs e)
  8. {
  9.   string[][] test = e.Argument as string[][];
  10.   Array.Resize(ref test,2);
  11.   Array.Resize(ref test[0],2);
  12.   Array.Resize(ref test[1],2);
  13.   test[0][0] = "first feed, first message";
  14.   test[0][1] = "first feed, second message";
  15.   test[1][0] = "second feed, first message";
  16.   test[1][1] = "second feed, second message";
  17.  
  18.   e.Result = test;
  19. }
  20.  
  21. void RunWorkerCompleted(object state, RunWorkerCompletedEventArgs e)
  22. {
  23.   //this never fires at all!!
  24.   string[][] test = e.Result as string[][];
  25.   textBox1.Text = test[0][0];
  26. }
  27.  
Stepping through the code, e.Result looks correct immediately after setting it in DoWork, but then the app hangs and RunWorkerCompleted never fires.

All help gratefully received.
Feb 21 '13 #1
0 1282

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Roger Davis | last post by:
I've been reading lately about the necessity of using delete p; instead of delete p; whenever p was allocated as an array, e.g.,
9
by: matthurne | last post by:
I need to send just an array to a function which then needs to go through each element in the array. I tried using sizeof(array) / sizeof(array) but since the array is passed into the function,...
5
by: Emmanuel Delahaye | last post by:
Hi, I know that C90 and C9x (N869) doesn't allow to define an array of size 0. int x; /* constraint violation */ I was under the impression that this was possible in C99, due to the common...
25
by: prashna | last post by:
Hi all, I have seen a piece of code(while doing code review) which declared an array of size 0.One of my friend told although it is not standard C,some compilers will support this..I am very...
5
by: jcrouse | last post by:
I have the following code: Dim MyStartupArguments() As String MyStartupArguments = System.Environment.GetCommandLineArgs UBound(MyStartupArguments) RomName =...
5
by: eagle_jyjh | last post by:
For example: the msg = temp_buf; is alwawys ok? //test_msg.cpp struct msg_head { char a01;
0
by: Cedric | last post by:
Hello, I 'm a bit confused about the size of an array of byte use by getjob or setjob. For GetJob no problem, API return size needed BUT for SetJob I must pass an array with good size. It's...
7
by: SUNIL TYATA | last post by:
The java code below is well functioning code where I did was; I used nums.length as the size for the declaring the new arrary within the function body. public int reverse3(int nums) { int...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.