473,765 Members | 2,034 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 1321

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

Similar topics

4
20911
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
10706
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
8800
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
2702
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
1914
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
2125
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
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
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...
0
8832
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
7379
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
6649
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();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.