MapInfo Pro Developers User Group

 View Only
  • 1.  Running MapBasic commands blocks the user interface

    Posted 04-22-2021 02:05
    Hello again group,

    I can now run MapBasic commands from a background thread in .NET without MapInfo crashing which is great.  However, I have come across another problem.

    I have a  MapBasic extension integrated with .NET that constantly updates a MapInfo map (I am aiming for a 100 millisecond update time).  However every time a MapBasic command is run the mouse cursor turns into a wait cursor and I cannot use the user interface, including my MBX UI and .NET WPF dialogs.  Because this is happening constantly, I cannot stop my extension from running and must force quit MapInfo.

    Does anyone have any suggestions about how to stop this from happening?  Ideally, the map would be updated in the background and I could freely use both the MapInfo UI and my MBX UI.

    Kind regards
    Ben

    ------------------------------
    Ben Kleywegt
    Insight GIS
    ------------------------------


  • 2.  RE: Running MapBasic commands blocks the user interface

    Employee
    Posted 04-22-2021 06:10
    Hi Ben

    Exactly what do you do for each update?
    If that takes more than 100 milliseconds, you are caught in a loop, right?

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Running MapBasic commands blocks the user interface

    Posted 04-22-2021 21:14

    Hi Peter,

    This is what I currently do in .NET for each update:

    mapInfoApplication.RunMapBasicCommand(String.Format("PRINT \"INSERT INTO tabGPSTracker(Latitude, Longitude, DateCreated, Obj) VALUES({0}, {1}, CurDateTime(), CreatePoint({1},{0}))\"", coord.Latitude, coord.Longitude));
    
    mapInfoApplication.RunMapBasicCommand(String.Format("INSERT INTO tabGPSTracker (Latitude, Longitude, DateCreated, Obj) VALUES ({0}, {1}, CurDateTime(), CreatePoint({1},{0}))", coord.Latitude, coord.Longitude));
    
    mapInfoApplication.RunMapBasicCommand(String.Format("Set Map Window FrontWindow() Center ({1}, {0}) Zoom 2", coord.Latitude, coord.Longitude));​

    It's not really caught in a loop because it's being called from .NET on a background thread (using Dispatcher.Invoke to call the MapBasic commands).  But because the commands are being executed in MapInfo on the main/UI thread it blocks user interaction.  Anyway, MapInfo certainly doesn't like it much! ;)

    Cheers
    Ben



    ------------------------------
    Ben Kleywegt
    Insight GIS
    ------------------------------



  • 4.  RE: Running MapBasic commands blocks the user interface

    Employee
    Posted 04-23-2021 01:55
    Hi Ben

    What I'm fearing is that the process you are running takes more than 100 milliseconds and therefore gets executed almost before the previous has finished.

    I have no real experience using background threads and MapInfo Pro so I can't tell if there is something obvious here.

    One thing to try out is to limit the work in the process to only do the print statement.
    Does that "free up MapInfo Pro"?

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 5.  RE: Running MapBasic commands blocks the user interface

    Posted 04-26-2021 02:18
    Thanks Peter.

    Yes, you are right.  If I only run a print statement every update it does appear to 'free up' MapInfo so that I can use the UI.

    ------------------------------
    Ben Kleywegt
    Insight GIS
    ------------------------------



  • 6.  RE: Running MapBasic commands blocks the user interface

    Employee
    Posted 04-26-2021 02:30
    I assume you need to create a method with a lighter footprint.

    I'd think you can update your table to show the new position of the point.
    Are you showing all the points as they get inserted? It will eventually be a lot of points if you add one for each 100 milliseconds.
    If you only want to show the latest, update the existing point with the new values instead of inserting a new (and potentially deleting the old).

    Also, make sure your layer with the points has been loaded as an Animation layer in the map, see the Add Map statement:
    Add Map
      [ Window window_id ] [ Auto ]
      Layer table [ , table [ Animate ] ... ]
      [ [ DestGroupLayer group_id ] Position position ]

    This will basically divide the map into two images. One with the animation layer and one with the rest of the layers. When the animation layer changes, only that image will get rendered again. This improves the map rendering.

    Try to avoid redrawing the map by changing the center for a start. Construct some rules that control when the entire map needs to get rendered. That could be when the point is too far from the center of the map.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 7.  RE: Running MapBasic commands blocks the user interface

    Employee
    Posted 04-26-2021 09:56
    I was going to post a similar reply about the animation layer but Peter beat me to it.
    So this is me agreeing with his post.

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 8.  RE: Running MapBasic commands blocks the user interface

    Posted 04-26-2021 21:40
    Thanks for your advice guys, that's great.

    Unfortunately, the project just got cancelled by the client but now I know for next time and maybe this helps someone else :(

    ------------------------------
    Ben Kleywegt
    Insight GIS
    ------------------------------