473,387 Members | 1,722 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,387 software developers and data experts.

invoke required keeps true

Hello all, i am making a multithreaded program which copies a file.
at the end of the file copy it will call a process to update a certain dropdownlist.
the following code will cause a stack overflow, i copied it from the MSDN library and took out the items i didnt need (parameters) and replaced it with my variables.

any help would be appreciated, it could well be that i overlooked something

Expand|Select|Wrap|Line Numbers
  1. delegate void LoadList();
  2.  
  3. private void loadList()
  4.         {
  5.             if (ddlTools.InvokeRequired)
  6.             {
  7.                 LoadList d = new LoadList(loadList);
  8.                 d.Invoke();
  9.             }
  10.             else
  11.             {
  12.                 //Clear our list
  13.                 ddlTools.Items.Clear();
  14.                 //Etc,,,
  15.             }
  16.         }
Mar 5 '09 #1
6 4852
tlhintoq
3,525 Expert 2GB
I'm going to bet you are looping endlessly really fast and running the stack out.

In the method loadList(), line 7 calls a new loadList(), which is itself, which then calls a new loadList() which is itself, which calls a new loadList() which is itself... get the idea?

Put a breakpoint at line 7 and step through it. I'll bet you see this getting called over and over.
Mar 5 '09 #2
yes, i know that far.
i also found out that d.invoke() will use the same thread
so i must use this.invoke(d)
*edit*
capitals are different
loadList
LoadList
Mar 5 '09 #3
tlhintoq
3,525 Expert 2GB
Right. LoadList keeps making a new loadList. Over and over and over because it keeps calling itself in line 7.

But it will only do this if the condition of line 5 is true.
Try this: insert a line between 6 and 7 that makes ddtool.InvokeRequired false. That way it will work the first time through, but be changed after it has done the first invoke.
Mar 5 '09 #4
i already fixed it by using this.invoke(d)
if i forced it to true i'd probably get a unsafe threadcall error since its still a different thread then the UI component (hence the eternal loop?)
Mar 5 '09 #5
mldisibio
190 Expert 100+
In order to marshal the thread back to the UI thread, it is the control which needs to call invoke on the delegate. This is different than just creating a new delegate and calling invoke on it, because, as tlhintoq says, that just keeps calling itself, and since the thread has not been marshalled yet, the InvokeRequired condition remains true.

Try the following:

Expand|Select|Wrap|Line Numbers
  1. delegate void LoadList();
  2.  
  3. private void loadList()
  4.         {
  5.             if (ddlTools.InvokeRequired)
  6.             {
  7.                 LoadList d = new LoadList(loadList);
  8.                 ddlTools.Invoke(d);
  9.             }
  10.             else
  11.             {
  12.                 //Clear our list
  13.                 ddlTools.Items.Clear();
  14.                 //Etc,,,
  15.             }
  16.         }
Mar 6 '09 #6
Plater
7,872 Expert 4TB
As long as the control used in the if statement is the same one used to .Invoke you should be fine.
I use "this" for both and it seems to work well enough
Mar 6 '09 #7

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

Similar topics

19
by: trint | last post by:
Ok, I start my thread job: Thread t = new Thread(new ThreadStart(invoicePrintingLongRunningCodeThread)); t.IsBackground = true; t.Start(); There are lots of calls to controls and many...
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
2
by: Lucvdv | last post by:
To avoid a temporarily frozen user interface, I'm using a separate thread to fill a list with items found in a database (there can be from a few up to about 1000 or 1500 items). There seems to...
7
by: Jeff Stewart | last post by:
I need a thread to run a subroutine which updates my main form's progress bar. I've properly marshaled all UI updates to the main UI thread, and after the main thread starts the worker thread, it...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i donīt want to filter the return value of the method, i have to pass a new instance of the...
1
by: Lore Leunoeg | last post by:
If I call a delegates BeginInvoke a new thread from the threadpool is started. But what happens if I call the Invoke method? Does this also start a new thread? Thank you sincerely Lore
6
by: k.mellor | last post by:
Hi, I hope someone can help. I have written a simple form to demonstrate my problem/question. The code follows. The form starts a thread, which using delegates updates a label (Every second...
11
by: Naeem | last post by:
I have a Javascript function, which changes a text field of a form into a select field. Following is the function function changeStateField() { var myForm =...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.