Page 1 of 1

InvalidOperationException

Posted: Thu Feb 15, 2007 5:43 pm
by 9090276
Hi,

Currently I'm working on an app and getting the following exception (The exception is cut and pasted to the end of this post.

I am unable to debug this because the exception happens outside of the application.

I noticed that someone else on the forum had the same problem, but the answer was never posted

I think the error might be due to the multi-threaded nature of my application, and if so, are there any rules when using teechart in a multi-threaded context?

I have placed locks around all points where i do a line.Add(), but that doesn't seem to solve the problem.

Thanks


See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayListEnumeratorSimple.MoveNext()
at Steema.TeeChart.Chart.InternalDraw(Graphics g)
at Steema.TeeChart.TChart.Draw(Graphics g)
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
TritonDotNetAPI
Assembly Version: 2.2.4.28041
Win32 Version: Version 3.1 Iteration 4 Build 8173
CodeBase: file:///C:/Program%20Files/ITG/Triton/TritonDotNetAPI.DLL
----------------------------------------
Interop.TritonFrontendLib
Assembly Version: 301.434.0.0
Win32 Version: 301.434.0.0
CodeBase: file:///C:/Program%20Files/ITG/Triton/Interop.TritonFrontendLib.DLL
----------------------------------------
Interop.TritonFrontendEventsLib
Assembly Version: 301.434.0.0
Win32 Version: 301.434.0.0
CodeBase: file:///C:/Program%20Files/ITG/Triton/Interop.TritonFrontendEventsLib.DLL
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
BlackHen.Threading
Assembly Version: 1.0.2594.19751
Win32 Version: 1.0.2594.19751
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/BlackHen.Threading.DLL
----------------------------------------
ICSharpCode.SharpZipLib
Assembly Version: 0.84.0.0
Win32 Version: 0.84.0.0
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/ICSharpCode.SharpZipLib.dll
----------------------------------------
ITGC Best Execution
Assembly Version: 1.3.0.0
Win32 Version: 1.3.0.0
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/ITGC%20Best%20Execution.DLL
----------------------------------------
System.Web.Services
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.web.services/1.0.5000.0__b03f5f7f11d50a3a/system.web.services.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
ITGC Triton Library
Assembly Version: 1.2.16.0
Win32 Version: 1.2.16.0
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/ITGC%20Triton%20Library.DLL
----------------------------------------
MDAPI
Assembly Version: 1.0.2001.24671
Win32 Version: 1.0.2001.24671
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/MDAPI.dll
----------------------------------------
PdfSharp
Assembly Version: 0.8.494.0
Win32 Version: 0.8.494.0
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/PdfSharp.DLL
----------------------------------------
TeeChart
Assembly Version: 2.0.2179.21171
Win32 Version: 2.0.2179.21171
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/TeeChart.dll
----------------------------------------
TimeZoneLibrary
Assembly Version: 1.0.2298.28278
Win32 Version: 1.0.2298.28278
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/TimeZoneLibrary.DLL
----------------------------------------
Interop.DssCOM
Assembly Version: 301.434.0.0
Win32 Version: 301.434.0.0
CodeBase: file:///C:/Program%20Files/ITG/Triton/Interop.DssCOM.DLL
----------------------------------------
System.Web
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2037
CodeBase: file:///c:/windows/assembly/gac/system.web/1.0.5000.0__b03f5f7f11d50a3a/system.web.dll
----------------------------------------
q55sj_wi
Assembly Version: 0.0.0.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
vb3ubpsu
Assembly Version: 0.0.0.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
Accessibility
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/accessibility/1.0.5000.0__b03f5f7f11d50a3a/accessibility.dll
----------------------------------------
System.Data
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.

Posted: Fri Feb 16, 2007 8:53 am
by 9348258
Hi itg

Could you please say to us what is the post it had the same problem, this can help us to understand the error. Or could you please send us a simple example project we can run "as-is" to reproduce the issue here?

You can post your files either at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup or at our upload page

Thanks in advance

Posted: Fri Feb 16, 2007 3:36 pm
by 9090276
Hi,


In terms of providing a simple project, I can only get it to work on my current project which is very large, and hard to give code samples

In terms of what the actual program is doing, what's happening is that there is currently one Steema TChart. Thread one is updating Lines 1 & Lines 2 on the chart, adn another Thread is updating Lines 3 & Lines 4.


The previous thread that I was referring to is in the link below:

http://www.teechart.net/support/viewtopic.php?t=437

Posted: Mon Feb 19, 2007 8:56 am
by narcis
Hi itg,

It's very difficult for us being able to help you on that without being able to reproduce the problem here or having more information about the problem.

Code: Select all

TeeChart
Assembly Version: 2.0.2179.21171
Win32 Version: 2.0.2179.21171
CodeBase: file:///C:/Program%20Files/ITG/Custom/Plugins/bin/ITGC%20Best%20Execution/TeeChart.dll
However, it seems you are using quite an old TeeChart version. Please notice that the latest maintenance release available at the client area is Build 2.0.2586.24038/9. Could you please try if this version solves the problem?

Thanks in advance.

I am seeing this same exception in TChart Version 3.5.3146.2

Posted: Fri Sep 26, 2008 10:26 pm
by 8739068
My problem occurs as a result of the TChart.OnPaint method call. The exception is at Steema.TeeChart.Chart.GetAxisSeries method.

My application is multithreaded as well. I have a thread that will do a Steema.TeeChart.Chart.Series.Clear(), and then start adding new CustomPoint series's. I see the InvalidOperationExcetpion, "Collection was modified; enumeration operation may not execute" occurring fairly regularly.

I have tried using the BeforeDraw and AfterDraw events to prevent any changes to the TeeChart.Series array from occurring while the chart is in the processing of drawing. This is not working.

Posted: Mon Sep 29, 2008 8:11 am
by narcis
Hi Mike,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.

Unable to post an example

Posted: Mon Sep 29, 2008 1:59 pm
by 8739068
I have spent 2 hours trying to come up with an example. Unfortunately it is very difficult to reproduce the problem in a simple example. Our application is fairly complex and would be impossible to send the entire project.

Any advice on how to debug this issue would be appreciated even if the advice is very general. I am fairly confident the problem stems from the TChart control doing some drawing and processing in one thread and then another thread comes along and does a Series.Clear(). An OnPaint method is called that invokess a call to a foreach on the Series collection and the series collection changed while processing the foreach. This is exactly what the exception tells me.

I mentioned before, I was trying to use the BeforeDraw and AfterDraw events to synchronize when a thread could do a Series.Clear. I was making sure it was after the AfterDraw event and before and BeforeDraw event. This did not seem to work for me.

I will continue to see if I can create a sample project, but given the complexity it is likely to be very difficult.

Keep in mind I have the source code and have been able to break on the exception and examine the code surrounding the exception.

My biggest question is when is it OK to call Series.Clear() and Series.Add() in a multi-threaded application?

Posted: Tue Sep 30, 2008 10:16 am
by narcis
Hi Mike,

All series are drawn after the BeforeDraw event is called and before the AfterDraw event is called. Can you reproduce the problem simply by trying to call Series.Clear() in a separate thread before BeforeDraw is called or after AfterDraw is called?

Thanks in advance.