#1 2012-11-26 18:35:05

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Per thread object instances

I got a service server, somewhat like sample 6, using HTTP.SYS

One of the services uses an object which is slow to create so it's created when the server starts and protected with a critical section.

This works but is there a way to create one instance of this object for each thread of the server and then access it from within the server's service function?

Offline

#2 2012-11-27 07:56:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Per thread object instances

You can either:
- use a threadvar variable;
- use ServiceContext.RunningThread property to retrieve the calling thread (and its ID);
- override TSQLRestServer.BeginCurrentThread() and TSQLRestServer.EndCurrentThread() to handle your server instance life time.

Offline

#3 2012-11-27 08:30:58

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Per thread object instances

Thank you, I'll investigate the best way

Offline

Board footer

Powered by FluxBB