Question

I am curious as to how to proceed with this issue; I currently have a DataSnap server setup with a TDSAuthenticationManager class managing the authentication.

If an authentication fails, is it safe for me to write directly onto a form TMemo or something similar for logging purposes? What's the best way to observe this?

Do I need threading?

Cheers for reading, Adrian

Was it helpful?

Solution

Yes, you need synchronization, since Datasnap events run in the context of different threads, and as you may know, the UI programming is limited to the main thread.

So, if you want to display something in the UI, you have to take care of how to do it.

On the other hand, if you want to log to a file, you don't need synchronization, but you have to be careful, since it is possible for two different threads to try to log at the same time.

The options I would evaluate are:

  • Protect the access to the log file using a Critical Section, thus avoiding the multi-thread access with a lock. Only one thread can access the file at a time and all other interested threads have to wait.
  • Create a new logging class, from which a global instance that can take log requests by simply adding the log message to a (multi thread capable) queue in memory, and running it's own thread writing them to a file when there are messages in the queue.

Since servers tend to run as a services in production environments, I would choose the latter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top