Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Saturday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Saturday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Jun 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Problems and Troubleshooting
c# httpListner HELP
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="HAneo" data-source="post: 28090979" data-attributes="member: 17432"><p>[USER=318958]@wpmanoj[/USER]</p><p></p><p>Ok, i did some modifications to the Code. removed the While Listening. and implement Callbacks. this way we don't have to wait for the requests but we will be notified upon the request hits the context. </p><p>and it's Async Now. you can have multiple requests at the same time </p><p></p><p></p><p>[CODE]</p><p>public void NonblockingListener()</p><p>{</p><p> _listener = new HttpListener();</p><p> _listener.Prefixes.Add("http://localhost/asynctest/");</p><p> _listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;</p><p></p><p> _listener.Start();</p><p> _listener.BeginGetContext(OnContext, null);</p><p></p><p> Console.ReadLine();</p><p> }</p><p>[/CODE]</p><p></p><p>[CODE]</p><p> private void OnContext(IAsyncResult ar)</p><p> {</p><p> try</p><p> {</p><p> var guid = Guid.NewGuid();</p><p> var ctx = _listener.EndGetContext(ar);</p><p> _listener.BeginGetContext(OnContext, null);</p><p></p><p> Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " Handling request");</p><p></p><p> var buf = Encoding.ASCII.GetBytes("Hello world - " + guid.ToString());</p><p> ctx.Response.ContentType = "text/plain";</p><p> ctx.Response.OutputStream.Write(buf, 0, buf.Length);</p><p> ctx.Response.OutputStream.Close();</p><p></p><p> Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " completed");</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " Error " + ex.Message);</p><p> }</p><p> }</p><p>[/CODE]</p><p></p><p>Now even with this change, I couldn't stop the memory from increasing. </p><p>See this.</p><p><img src="https://i.postimg.cc/y6JqHSNp/Mem-Profile1.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p></p><p>Then I analyze what has happened. you can see where the increase or decrease happens(analysis 2 snapshots and see the difference)</p><p></p><p><img src="https://i.postimg.cc/28wgdd96/Mem-Profile2.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p></p><p>So the Root of the problem is above 1 and 2. these both cause a memory leak. and as per the MS words, you cannot do anything about this. they always leaking a few Bytes per request. if logic gets complex this may leak from bytes to KB easily. you cannot do anything to this. because these are the .NET Runtime and OS API calls. both of them are in the Unmanaged stack which you or I never can access. </p><p></p><p>Read these articles </p><p></p><p><a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/068ac24e-1ede-47d6-8ef8-9aee73eed4ab/memory-leak-involving-systemreflectionruntimemodule?forum=netfxbcl" target="_blank">https://social.msdn.microsoft.com/Forums/vstudio/en-US/068ac24e-1ede-47d6-8ef8-9aee73eed4ab/memory-leak-involving-systemreflectionruntimemodule?forum=netfxbcl</a></p><p></p><p><a href="https://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak" target="_blank">https://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak</a></p></blockquote><p></p>
[QUOTE="HAneo, post: 28090979, member: 17432"] [USER=318958]@wpmanoj[/USER] Ok, i did some modifications to the Code. removed the While Listening. and implement Callbacks. this way we don't have to wait for the requests but we will be notified upon the request hits the context. and it's Async Now. you can have multiple requests at the same time [CODE] public void NonblockingListener() { _listener = new HttpListener(); _listener.Prefixes.Add("http://localhost/asynctest/"); _listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous; _listener.Start(); _listener.BeginGetContext(OnContext, null); Console.ReadLine(); } [/CODE] [CODE] private void OnContext(IAsyncResult ar) { try { var guid = Guid.NewGuid(); var ctx = _listener.EndGetContext(ar); _listener.BeginGetContext(OnContext, null); Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " Handling request"); var buf = Encoding.ASCII.GetBytes("Hello world - " + guid.ToString()); ctx.Response.ContentType = "text/plain"; ctx.Response.OutputStream.Write(buf, 0, buf.Length); ctx.Response.OutputStream.Close(); Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " completed"); } catch (Exception ex) { Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " Error " + ex.Message); } } [/CODE] Now even with this change, I couldn't stop the memory from increasing. See this. [IMG]https://i.postimg.cc/y6JqHSNp/Mem-Profile1.png[/IMG] Then I analyze what has happened. you can see where the increase or decrease happens(analysis 2 snapshots and see the difference) [IMG]https://i.postimg.cc/28wgdd96/Mem-Profile2.png[/IMG] So the Root of the problem is above 1 and 2. these both cause a memory leak. and as per the MS words, you cannot do anything about this. they always leaking a few Bytes per request. if logic gets complex this may leak from bytes to KB easily. you cannot do anything to this. because these are the .NET Runtime and OS API calls. both of them are in the Unmanaged stack which you or I never can access. Read these articles [URL]https://social.msdn.microsoft.com/Forums/vstudio/en-US/068ac24e-1ede-47d6-8ef8-9aee73eed4ab/memory-leak-involving-systemreflectionruntimemodule?forum=netfxbcl[/URL] [URL]https://docs.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak[/URL] [/QUOTE]
Insert quotes…
Verification
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom