0

I have an application pool that has multiple worker processes (e.g 4). Is there somehow any way to access the website, such that you know you are always on worker process #1, or #2, etc?

I need to do specific tasks like clearing memory cache on a particular worker process, and since you don't know which one you are on, I'm finding it a problem to clear the cache for all the worker processes.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Karl Cassar
  • 6,043
  • 10
  • 47
  • 84
  • Take a look to this question: http://stackoverflow.com/questions/13012414/can-i-get-the-process-id-of-a-worker-process-in-a-web-application – ADreNaLiNe-DJ Jan 29 '16 at 09:42
  • @ADreNaLiNe-DJ - That will only get me the process id. I want to access the process specifically, for example if it was differentiated by port (which I know isn't), I would do something like http://127.0.0.1:9001 (process 1) and http://127.0.0.1:9002 (process 2), and http://127.0.0.1 would do the 'load-balancing' kind-of between processes. – Karl Cassar Jan 29 '16 at 10:03
  • Once you have the PID, you can execute some tasks on it like killing (even if it's not your need): http://weblogs.asp.net/scottgu/Tip_2F00_Trick_3A00_-Command_2D00_line-Tasklist_2F00_Taskkill-Utilities- – ADreNaLiNe-DJ Jan 29 '16 at 10:33
  • With this link (https://msdn.microsoft.com/fr-fr/library/microsoft.web.administration.applicationpool.workerprocesses(v=vs.90).aspx), you can access the list of worker processes associated to an application pool. With the PID o f the worker process, you are able to retreive the worker process in the collection then you can call "Finalize" on the workerprocess to force freeing resources. Also take a look to this answer about ApplicationPool action from c# code: http://stackoverflow.com/a/249942/5119765 – ADreNaLiNe-DJ Jan 29 '16 at 11:12
  • I don't want to kill the process, I want to be able to access the website always on a specific worker process. Killing it would technically work, but it would be good if I can know I'm accessing process #1 or process #2. Those solutions address a different solution, i.e killing the task. Retrieving the worker processes as @ADreNaLiNe-DJ pointed out might work, if somehow there can be any inter-process communication. Still not idea, but could work. – Karl Cassar Jan 29 '16 at 12:46

1 Answers1

0

Make a request loop until System.Diagnostics.Process.GetCurrentProcess().Id returns the process you want to work with.