Working with Backgroundworker

Topics: Help
Jul 18, 2013 at 3:57 PM
Hello,

I am updating the map with Backroundworker.

Got that error

bei System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
bei System.Collections.Generic.List1.Enumerator.MoveNextRare()
bei System.Collections.Generic.List
1.Enumerator.MoveNext()
bei GMap.NET.WindowsForms.GMapControl.OnPaintOverlays(Graphics g)
bei GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
bei System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
bei System.Windows.Forms.Control.WmPaint(Message& m)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
bei System.Windows.Forms.UserControl.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.RunDialog(Form form)
bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
bei System.Windows.Forms.Form.ShowDialog()
bei iBusClient.MapControl.BarButtonItem1_ItemClick(Object sender, ItemClickEventArgs e) in C:\Source\iBusClient\iBusClient\Controlls\MapControl\MapControl.vb:Zeile 91.
bei DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
bei DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
bei DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
bei DevExpress.XtraBars.BarItemLink.OnLinkClick()
bei DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
bei DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
bei DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
bei DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
bei DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
bei DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
bei DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei DevExpress.XtraBars.Controls.CustomControl.WndProc(Message& msg)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)

What to do?

Best Regards

Gerhard
Coordinator
Jul 19, 2013 at 6:21 AM
check demo source
Jul 19, 2013 at 7:24 AM
I think it's multi thread thing.
One thread wants to change overlays and on thread wants to read it.
I think it depends on the actions at a specific time.

Is there a way to stop gmap.net working, while the application changes
overlays?

Best Regards

Gerhard
Coordinator
Jul 19, 2013 at 7:52 AM
use ui thread for ui operations
Jul 19, 2013 at 9:15 AM
I think the ui thread (gmap.net) reads a data structure (overlays) to update the view.
At the same moment the working thread changes that data structure.

The same error occurs if you make a for each loop over a data structure
and you changes the data structure with in the loop.

One solution is to stop ui thread working. Is there a way to stop gmap.net while updateing?

Best Regards

Gerhard
Coordinator
Jul 19, 2013 at 9:20 AM
the solution is: use ui thread for ui operations
Jul 19, 2013 at 9:28 AM
Is changing overlays and Gmaproutes a ui operation for gmap.net?

Best regards

Gerhard
Coordinator
Jul 19, 2013 at 9:52 AM
almost everything relating map is ui operation
Jul 19, 2013 at 11:07 AM
If I don't add GMapRoutes and Overlays in the Background process, there is no error.

But how can the background process communicate with the ui process to tell it
to add GMapRoutes and Overlays?

Best Regards

Gerhard
Jul 19, 2013 at 11:24 AM
I got the solution:

Private Sub AddOverlay(ByVal overlay As GMapOverlay)
    if _gMapControl.InvokeRequired Then
        _gMapControl.Invoke(New Action(Of GMapOverlay)(AddressOf AddOverlay), overlay)
    Else
        _gMapControl.Overlays.Add(overlay)
    End If
End Sub

To use the standard ui invoke pattern works.

Best regards

Gerhard