473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackgroundWorke r not triggering RunWorkerComple ted if Argument (array) changes size

1 New Member
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, RunWorkerComple ted 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 RunWorkerComple ted 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 RunWorkerComple ted never fires.

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

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

Similar topics

4
20910
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
10703
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, sizeof(array) is really sizeof(pointer to first element in array) and therefore doesn't solve my problem. If I can't calculate the size of the array, can I go through the elements without knowing the size and somehow test whether I'm off the end...
5
8799
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 C90 practice: struct a
25
2698
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 curious to know the use of it.. The code was compiled using Diab C compiler. Also the array was declared in structure like this typedef struct someStruct
5
1912
by: jcrouse | last post by:
I have the following code: Dim MyStartupArguments() As String MyStartupArguments = System.Environment.GetCommandLineArgs UBound(MyStartupArguments) RomName = (MyStartupArguments(0).ToString) ParentName = (MyStartupArguments(1).ToString)
5
2123
by: eagle_jyjh | last post by:
For example: the msg = temp_buf; is alwawys ok? //test_msg.cpp struct msg_head { char a01;
0
908
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 seems that API need extra space for storing string. In the structure all members are integer or IntPtr and Marshal.SizeOf return a size of 104 but GetJob return size like 1000. So my question is : If I modify a string that will be used by the API,...
7
2671
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 temp = new intnums.length]; for(int i=0;i<nums.length;i++) { temp = nums;
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.