2

If I have 2 Asp.Net websites running on my machine and 2 PowerShell windows open, how many instances of the Static class System.Net.ServicePointManager are there?

One per machine? One per Application Domain? One per Process?

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61
  • You could try it out and see what happens when writing in one app and reading in another. – Uwe Keim Jun 04 '19 at 09:08
  • See also [this answer](https://stackoverflow.com/a/5986060/107625). – Uwe Keim Jun 04 '19 at 09:09
  • 1
    Pretty sure it's app domain, but I can't find any proof. – DavidG Jun 04 '19 at 09:11
  • 1
    We have [this](https://learn.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.defaultconnectionlimit) that mentions app domain. – DavidG Jun 04 '19 at 09:13
  • 2
    Possible duplicate of [How to use SSL3 instead of TLS in a particular HttpWebRequest?](https://stackoverflow.com/questions/3028486/how-to-use-ssl3-instead-of-tls-in-a-particular-httpwebrequest). Not 100% duplicate, but the accepted answer gives your answer. – DavidG Jun 04 '19 at 09:15
  • Hmm. Okay, so yes the C# spec does answer the question by searching it for 'application domain' and 'static variables' so I added up-to-date links to the answer @UweKeim pointed to. Which perhaps just leaves me assuming that powershell is one application domain per window. I think my uncertainty stemmed from thinking, network Stuff is potentially a passthrough to the underlying O/S so maybe it was per-machine. – Chris F Carroll Jun 04 '19 at 09:35
  • 1
    @ChrisFCarroll Powershell isn't just one domain per window, it's different processes. This has nothing to do with *.NET*, it's how the console subsystem on Windows works. What you see isn't powershell. It's a terminal that talks to the Console Host, which in turn talks to Powershell. – Panagiotis Kanavos Jun 04 '19 at 09:44
  • 1
    @ChrisFCarroll Rich Turner's [Windows Command-Line: Inside the Windows Console](https://devblogs.microsoft.com/commandline/windows-command-line-inside-the-windows-console/) explains how this works, what the problems were up to now and how this changes in Windows 10, leading up to the new [Windows Terminal](https://devblogs.microsoft.com/commandline/introducing-windows-terminal/). With Powershell, and soon the old `CMD` processor, the *process* can easily be on a different machine entirely – Panagiotis Kanavos Jun 04 '19 at 09:48
  • 1
    4: you have 4 processes, none of which share memory. Neither PowerShell nor ASP.NET Core use AppDomains, so that simplifies the question. Having said that, on .NET (not .NET Core) `ServicePointManager` reads defaults from the configuration file and the registry. It never writes anything, but this is one way to get different `ServicePointManager`s to "think" the same. You don't have to fear (or hope) that setting anything in one `ServicePointManager` will influence another, though. – Jeroen Mostert Jun 04 '19 at 11:57
  • Moving on then … although you've all commented not answered, I think the Q&A is worth recording? – Chris F Carroll Jun 04 '19 at 14:59

1 Answers1

2

Nothing in the docs suggest that the ServicePointManager instance is anything other than a standard static instance.

Normal rules should apply: It is destroyed when the Application Domain is destroyed and we infer that there is one-per-Application Domain.

You can verify for PowerShell by opening two powershell Windows and typing

[System.Net.ServicePointManager]::DefaultConnectionLimit--; [System.Net.ServicePointManager]::DefaultConnectionLimit

in one of them and

[System.Net.ServicePointManager]::DefaultConnectionLimit++; [System.Net.ServicePointManager]::DefaultConnectionLimit

in the other.

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61