MapInfo Pro Developers User Group

Expand all | Collapse all

.Net Background Worker Thread

  • 1.  .Net Background Worker Thread

    Posted 02-04-2019 04:41
    Hi all,

    I'm trying to call  a MapBasic function through .Net  to register a .txt file as a table.
    MapInfoProAddInBase.CallMBFunction("RegisterTXTFile", "file.txt,tableName,tableAlias," + true);

    My problem is, when I call this from a BackgroundWorker it does't work.  I can reach the function. but at some point it just stop working.

    Register Table gsOutputFolder + stxtfile TYPE ASCII Delimiter 44 Charset "WindowsLatin1" Into ctemppath & "AAA.TAB"
    Open Table ctemppath & "AAA.TAB" Interactive

    This first line works. but after that is stops.

    Any idea why is that happening?


    PS. If I call this from my main thread it works.

    Nuno Seixas
    Buchanan Computing Ltd

  • 2.  RE: .Net Background Worker Thread

    Posted 02-06-2019 13:12
    Hi Nuno.

    MapBasic statement execution in MapInfoPro isn't a thread safe operation so we don't really support invoking  the commands from a secondary thread. We actually have an item on our backlog to establish better best practices, and generate better errors in the event the AddIn attempts to execute MB on a background thread. Since MIPro is only thread safe in limited operations, the expectation is that, even if we allowed the MB statement to be executed from a background thread, we would necessarily marshall the execution to the main thread anyway. At the moment, as you've discovered, we don't prevent the execution of the statement, but it's not a safe operation.

    It seems as if, in your case, the Register Table command was successful, but the Open Table... Interactive was not (and I wouldn't expect this to work).

    Just as a side-note, the MapInfo Data Access Library (MDAL) is thread safe and may be used in .NET add-in to open tables on a background thread...but tables opened via MIPro/MapBasic itself are necessarily opened on the main thread.


    John Teague
    Troy NY