problem in updating markers

Topics: Windows Forms
Jan 5, 2013 at 6:16 AM


I'm updating marker positions every 5 seconds.

sometimes the following error occurs and the map component turn into a white component with a red cross sign.

why this happens?

Collection was modified; enumeration operation may not execute. At    at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at GMap.NET.WindowsForms.GMapOverlay.OnRender(Graphics g)
   at GMap.NET.WindowsForms.GMapControl.OnPaintOverlays(Graphics g)
   at GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



Jan 7, 2013 at 11:32 AM

do you update the position from another thread?

Jan 7, 2013 at 9:46 PM

How do you update the position?  Are you by chance removing or adding new markers in a thread other than the GUI thread? 

Feb 4, 2013 at 7:51 AM
i was updating in a thread
now I'm updating it in a timer with interval of 30000
but some times the problem is happening
i will clear all markers first
then add all of new positions into marker collection
how should i update this ?
please help me with code
cause I'm fetching positions from a database on other PC via network and need to prevent my application from hanging.
Feb 4, 2013 at 11:21 AM
there are 3 real time demos handling thousand of markers, never hangs, just check the source
Feb 7, 2013 at 8:11 AM
is there any way to use a lock or something like that and update the markers in another thread?
i don't want my form to be hanged
Feb 7, 2013 at 9:28 AM
update takes just a few milliseconds, use backgroundworker
Feb 7, 2013 at 9:51 AM
radioman wrote:
update takes just a few milliseconds, use backgroundworker
i used background worker but nothing good happens
would you please give me a sample code for updating it?
Feb 7, 2013 at 9:58 AM
Feb 7, 2013 at 10:10 AM
radioman wrote:
i mean using a background worker.
have u ever tried that with GMAP.NET?
Feb 7, 2013 at 10:58 AM
Edited Feb 7, 2013 at 10:58 AM
i think thats counts as yes ;}
 #region -- demo workers --
            // flight demo
               flightWorker.DoWork += new DoWorkEventHandler(flight_DoWork);
               flightWorker.ProgressChanged += new ProgressChangedEventHandler(flight_ProgressChanged);
               flightWorker.WorkerSupportsCancellation = true;
               flightWorker.WorkerReportsProgress = true;

            // vehicle demo
               transportWorker.DoWork += new DoWorkEventHandler(transport_DoWork);
               transportWorker.ProgressChanged += new ProgressChangedEventHandler(transport_ProgressChanged);
               transportWorker.WorkerSupportsCancellation = true;
               transportWorker.WorkerReportsProgress = true;

            // Connections
               connectionsWorker.DoWork += new DoWorkEventHandler(connectionsWorker_DoWork);
               connectionsWorker.ProgressChanged += new ProgressChangedEventHandler(connectionsWorker_ProgressChanged);
               connectionsWorker.WorkerSupportsCancellation = true;
               connectionsWorker.WorkerReportsProgress = true;

               ipInfoSearchWorker.DoWork += new DoWorkEventHandler(ipInfoSearchWorker_DoWork);
               ipInfoSearchWorker.WorkerSupportsCancellation = true;

               iptracerWorker.DoWork += new DoWorkEventHandler(iptracerWorker_DoWork);
               iptracerWorker.WorkerSupportsCancellation = true;