Is the Message object thread safe? (.Net)

net
(estebanp) #1

.Net clients on a Delphi server.

I need to have all the client connections from different services to be using the same ClientId so they can be recognized as part of the same session.

If I manually set the ClientID to the same GUID

e.g.Connection.Message.ClientId=LoggedConnection.Message.ClientId

It works, but I set all the connections to match the logged connection on creation of the message object via injection but somewhere along the way of instantiation and after logging in, it gets changed and the clients do not hold the updated value anymore.

So to save me some headaches, If I do something like

Clientconnection1.Message = LoggedConnection.Message;
ClientConnection2.Message = LoggedConnection.Message;

Will this be thread safe? does it clones the message internally? if not, does it locks it access or it is not thread safe at all?

0 Likes

(marc hoffman) #2

iirc you will need separate message objects, just set to the same id.

0 Likes

(antonk) #3

Starting with v9.5 message instances are cloned by default when a remote server call is performed.

This behavior can be disabled via the CloneMessage property of the service proxy class, however it is strongly not advised to do.

At the same time concrete Message instances are NOT thread safe, i.e. it is not safe to use the same message instance from different threads simultaneously.

0 Likes