Opening databases global/local when using asynchrone methods

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Opening databases global/local when using asynchrone methods

Post by ic2 »

When we started Cavo programming many years back, we quickly adopted opening often used database globally. Opening and closing them in a specific screen (class) or even a method was simply costing too much time and added a lot of code.

In X# we could (I understand) add asynchrone code. I can imagine that this could give problems; in a DBF the recordpointer could have been set to specific record to be updated by one procedure while an asynchrone method could change this record pointer in the global database so the wrong record can be updated in the mentioned first procedure.

We use ADS and often new code is done with SQL statements. But that doesn't change the question. I am not sure if it does on using another SQL based database.

How do others deal with that?

Dick
leon-ts
Posts: 429
Joined: Fri Feb 03, 2017 1:43 pm

Opening databases global/local when using asynchrone methods

Post by leon-ts »

Hi Dick,
If an application keeps some workarea open for shared use, then I see two ways to solve this problem for asynchronous access:
1. Do not work directly with the shared workarea in the application code, but wrap it in some static class with the necessary set of methods. Within each method there must be a BEGIN LOCK ... END block when interacting with this workarea.
2. As far as I know, in X# a separate DataSession is allocated for each thread. As a result, each thread has its own independent set of workareas. Thus, each thread can independently open its shared workarea within the thread. In this case, synchronization when accessing the workarea is not needed.

Best regards,
Leonid
Best regards,
Leonid
Post Reply