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

C# Impossible error...

Airslash
221 100+
Hello,

I have a Mdi parent form that contains a List with objects as datamember. I'm trying to get the list inside a combobox on a mdi child form.

I'm using the following code:

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < ((frmMain)this.MdiParent).AssignmentStatus.Count; i++ )
  2.             {
  3.                 // Add the method in a save way.
  4.                 if (true == this.InvokeRequired)
  5.                 {
  6.                     this.BeginInvoke(new MethodInvoker(delegate()
  7.                     {
  8.                         this.cmbstatus.Items.Add(((frmMain)this.MdiParent).AssignmentStatus[i]);
  9.                     }
  10.                     ));
  11.                 }
  12.                 else
  13.                 {
  14.                     this.cmbstatus.Items.Add(((frmMain)this.MdiParent).AssignmentStatus[i]);
  15.                 }
  16.             }
  17.  
Now I have 2 errors occuring which shouldn't be even happening:
- The method enters the beginInvoke part, although the this.InvokeRequired is false (checked it with debug)
- The method is executed with i = 6, while the .Count method returns 6. So according the for loop this shouldn't even be possible.
Dec 11 '07 #1
5 1165
kenobewan
4,871 Expert 4TB
Looks like syntax error. Is the count zero indexed?
Dec 11 '07 #2
Airslash
221 100+
Looks like syntax error. Is the count zero indexed?
Count returns the amount of elements inside the list, so 6 would mean the list counts from 0 -> 5

Because I use i < .Count it should never reach 6, and have 5 as maximum value. The exact code works for all my other lists that I used, yet on this tiny bit it acts completly weird...
Dec 11 '07 #3
Plater
7,872 Expert 4TB
Hmm the only thing i can think of is when the loop "ends" i=6 (that's the break condition) and since you called the function with i maybe it's using this new value of i by the time it comes around to performing the action?
Dec 11 '07 #4
Airslash
221 100+
Thats what I had in mind as well, but that goes against the logic of a for loop...

Although the problem might lie in the MultiThreading environment.
Dec 12 '07 #5
Plater
7,872 Expert 4TB
Well there's no telling when in the scheme of things that invoke call will execute either.
I am pretty sure do to the nature of what it's doing, a breakpoint will always show opposing logic
Dec 12 '07 #6

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

Similar topics

4
by: Piotre Ugrumov | last post by:
I have tried to modify my exercise about the simulation of the life in the savannah. Now I have only 2 errors but I don't comprehend how resolve these errors. If I try to call the method getX() and...
7
by: Paul | last post by:
Hi, I have a problem with the C++ spec 14.7.3.15 (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14761 for relevant discussion). It seems that the code (below) is impossible to get right, as...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
4
by: David Sworder | last post by:
Hi there, I come from a Visual C++ background. When writing a service that's exposed to the Internet, I had to check the incoming data stream (from the client) VERY carefully. If a hacker was...
0
by: Karen | last post by:
I am trying to use VC++ 2003 .NET to add the OnQueryEndSession event handler to an MFC Dialog program using the Messages button of the Dialog properties window. I keep getting the message, Add/Remove...
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
4
by: URGENT..Please | last post by:
Hi folks, I really wonder who will solve this proble.Because I have searched many web sites (including MSDN.MICROSOFT.COM) and have found NO answer. When I try to open a new ASP.NET project an...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
2
by: Cat | last post by:
I created a web site, and I thought I followed XHTML 1.1 rules. But when I validated the pages, I got some error messages. I found that those codes are automatically generated parts by ASP.NET. ...
9
by: Gabriel | last post by:
Hello, I installed SQL server 2005 SP1 on a Windows XP SP2 From Visual Studio, I'm trygin to create a connection to a database, but I receive this error but I'm creating the connection (I...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
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,...

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.