Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Invalid index exception (Read 6176 times)
mison
YaBB Newbies
*
Offline



Posts: 4
Joined: Oct 19th, 2006
Invalid index exception
Oct 19th, 2006 at 1:41am
Print Post  
Hi, we're currently evaluating Planner.NET if we can use it within our application that has scheduling requirements.  So far, we've been very happy with the functionalities that we're getting from Planner.NET especially recurrence.

Right now, we're almost sure that we'll use your control but we want to verify this quite intermittent exception that we're getting with Planner.NET.

Just a background of what the application is doing when this exception is thrown... basically we have a multithreaded app that "listens" for messages to come into the app.  Messages correspond to appointments in Planner.NET.  When this exception is thrown, my thinking is that there are multiple threads trying to create an appointment in Planner.NET.

My question now is, is there something I should do to make Planner.NET thread-safe?

Please refer to the exception below for details...

Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range.  Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at MindFusion.Scheduling.WinForms.CellCollection.get_Item(Int32 index)
   at MindFusion.Scheduling.WinForms.ScheduleCell.Draw(DrawContext context)
   at MindFusion.Scheduling.WinForms.Calendar.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+I
MsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
  
Back to top
YIM  
IP Logged
 
mison
YaBB Newbies
*
Offline



Posts: 4
Joined: Oct 19th, 2006
Re: Invalid index exception
Reply #1 - Oct 19th, 2006 at 1:48am
Print Post  
By the way, we also got this error today:

Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.ArrayListEnumeratorSimple.MoveNext()
   at MindFusion.Scheduling.WinForms.DayCell.x0ae496095d389ba7(Boolean& x2fef7d841879a711)
   at MindFusion.Scheduling.WinForms.DayCell.Draw(DrawContext context)
   at MindFusion.Scheduling.WinForms.Cell.Draw(DrawContext context)
   at MindFusion.Scheduling.WinForms.MonthCell.Draw(DrawContext context)
   at MindFusion.Scheduling.WinForms.Calendar.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+I
MsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at MyCompanion.LogIn.Main() in c:\accelamycompanion v1\mycompanion\login.cs:line 67The program '[5764] MyCompanion.exe' has exited with code 0 (0x0).
  
Back to top
YIM  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Invalid index exception
Reply #2 - Oct 19th, 2006 at 6:52am
Print Post  
Unfortunately, Planner.NET is not thread-safe. It is your responsibility to ensure that only one thread performs actions on the control's data at a time (such as adding or removing appointments). You can, however, use the Control.Invoke method to execute actions on the thread owning the control's window handle. For example instead of directly calling Calendar.Schedule.Items.Add to add a new appointment to the calendar from a dedicated thread, you can instead use the following technique:

Define a method in your class that adds an appointment to the calendar.
Code
Select All
private void AddApp(Appointment a)
{
  calendar.Schedule.Items.Add(a);
} 


Define a delegate corresponding to this method.
Code
Select All
private delegate void AppDelegate(Appointment a); 


When you need to add an appointment, you do so by calling Invoke on the Planner.NET control.
Code
Select All
calendar.Invoke(new AppDelegate(this.AddApp), new object[] { a }); 


Meppy
  
Back to top
 
IP Logged
 
mison
YaBB Newbies
*
Offline



Posts: 4
Joined: Oct 19th, 2006
Re: Invalid index exception
Reply #3 - Oct 19th, 2006 at 11:57pm
Print Post  
Thanks Meppy.

I'll try this out with our code.  I assume that the same applies to adding DayStyles or any kind of add with the control, correct?

Will let you know what happens.
  
Back to top
YIM  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Invalid index exception
Reply #4 - Oct 20th, 2006 at 5:19am
Print Post  
Yes, you have to use the same technique whenever you are modifying the calendar data to prevent simultaneous modifications.

Meppy
  
Back to top
 
IP Logged
 
mison
YaBB Newbies
*
Offline



Posts: 4
Joined: Oct 19th, 2006
Re: Invalid index exception
Reply #5 - Oct 25th, 2006 at 5:16am
Print Post  
I'm very happy with the results.  After moving all the [b]Adds[/b] into the delegate, the error no longer happens.

My question now is that there are times the the control doesn't show all the added items.  You have to hide/show the window first to have the control redraw.  I've added .Invalidate in all the item add delegates but there are times that this problem still happens.  Any ideas?

Thanks again.
  
Back to top
YIM  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Invalid index exception
Reply #6 - Oct 25th, 2006 at 5:45am
Print Post  
The control should redraw itself whenever an item is added to it, there is no need to call Invalidate. Still, I have no idea what is the possible reason for this behavior. Would it possible for you to provide me with a sample code that produces this bug?

Meppy
  
Back to top
 
IP Logged
 
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Re: Invalid index exception
Reply #7 - Dec 20th, 2007 at 11:55am
Print Post  
Meppy can I run this by you please?

You say it is the develpers responsibility to ensure no simultaenious updates take place on the controls data and that using delegates is a way to handle this.

I do not know anything about delegates so will need to read up on them

However, my application will have its data in an SQL Server .mdf file on a file server.

All the required SQL Server guff will be included as part of the VB application installed onto the users computers.

I was under the impression that SQL Server would take care of the data collisions?

Am I wrong?

Thanks
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Invalid index exception
Reply #8 - Dec 20th, 2007 at 12:39pm
Print Post  
You have to use the techniques described in this topic only if you are modifying the calendar from a thread other than the one that have created it.

Otherwise, I am not really sure what is the actual problem you got.

Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint