A
Alphapage
Hello,
I have a class MyWorker.
Each time I create a new instance of MyWorker, I queue it to the ThreadPool.
So, 1 MyWorker object is pooled and belongs to its thread (there can't have 2
MyWorker in 1 thread from the ThreadPool).
When MyWorker is initialized or instanciate, I use an asynchronous delegate
to execute a long running process (depending on users, the job can be
quicker). So, this async delegate will use or create a new thread from the
ThreadPool to execute.
The MyWorker thread must wait for this async delegate to complete,the async
delegate thread will free up and will return to the ThreadPool, finally the
MyWorker object is able to continue processing with the result of the async
delegate.
But that means each MyWorker use 2 threads during long running process: I
think my app is bad design and can be optimized.
To increase the scalability, I heard about a kind of long running delegates
manager. But I can't find such a tool: I only find "fire-and-forget"
delegate which will corrupt MyWorker object because it doesn't wait for the
async delegate to complete or the same process I describe and use.
I need help to build a robust code implementing those features:
- queue each MyWorker in the ThreadPool
- each time the async delegate of MyWorker is invoked, free the MyWorker
thread to let other MyWorker object or other async delegate use it
- after the async delegate is completed and the thread is free, continue and
finalize the MyWorker process. (I think the long running delegates manager
will run on the Main app thread)
Thanks in advance for your help.
I have a class MyWorker.
Each time I create a new instance of MyWorker, I queue it to the ThreadPool.
So, 1 MyWorker object is pooled and belongs to its thread (there can't have 2
MyWorker in 1 thread from the ThreadPool).
When MyWorker is initialized or instanciate, I use an asynchronous delegate
to execute a long running process (depending on users, the job can be
quicker). So, this async delegate will use or create a new thread from the
ThreadPool to execute.
The MyWorker thread must wait for this async delegate to complete,the async
delegate thread will free up and will return to the ThreadPool, finally the
MyWorker object is able to continue processing with the result of the async
delegate.
But that means each MyWorker use 2 threads during long running process: I
think my app is bad design and can be optimized.
To increase the scalability, I heard about a kind of long running delegates
manager. But I can't find such a tool: I only find "fire-and-forget"
delegate which will corrupt MyWorker object because it doesn't wait for the
async delegate to complete or the same process I describe and use.
I need help to build a robust code implementing those features:
- queue each MyWorker in the ThreadPool
- each time the async delegate of MyWorker is invoked, free the MyWorker
thread to let other MyWorker object or other async delegate use it
- after the async delegate is completed and the thread is free, continue and
finalize the MyWorker process. (I think the long running delegates manager
will run on the Main app thread)
Thanks in advance for your help.