CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    120

    Terminate implicit session w/linq?

    Hello, experts!

    I need help with a scenario:

    I have a photography server that builds image paths dynamically to clients for downloading. This works as intended except for the following:

    Each time a viewer wants an image preview, a new session is created on the server, terminating only one hour later. When there is lots of traffic, the sessions accumulate, and end up overwhelming the server.

    I initially loaded the image uri more or less like this:

    Code:
    -- snip --
    string xmlSourceUrl = GetImageUrl( );
    
    XElement sourceRoot = XElement.Load( xmlSourceUrl );
    
    string result = ( from file in sourceRoot.Descendants( "PreviewUrl" ) select sourceRoot.Value ).Single< string >( );
    -- snip --
    Which is bad. It looks like linq for Xml supports loading xml directly over http, but there is no way to tell it afterwards that the session should end immediately.

    I tried using a WebClient object, but I cannot find a "Terminate", "Close", "Abandon" or any other function to indicate that I would like the session to end immediately after reading the stream.
    Here is how it looks:
    Code:
    			// Create a webclient object to read with
    			WebClient wc = new WebClient( );
    			
    			// prepare a reader object
    			TextReader reader = new StreamReader( wc.OpenRead( completeUrl ) );
    
    			/// To XElement using the reader
    			XElement result = XElement.Load( reader , LoadOptions.None );
    
    			// Close the reader
    			reader.Close( );
    
    			// client goes out of scope here - does session terminate?
    			return result;
    Can anyone help please?
    Last edited by Efitap; October 19th, 2008 at 06:51 AM.

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Terminate implicit session w/linq?

    I tried using a WebClient object, but I cannot find a "Terminate", "Close", "Abandon" or any other function to indicate that I would like the session to end immediately after reading the stream.
    You're looking for WebClient.Dispose ();

    Once you add that dispose, it looks like everything should fine. If there are memory problems, it's from other parts of your code.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    120

    Re: Terminate implicit session w/linq?

    Thank you for your reply. Do you mean to say that manually calling the Dispose object on the WebClient object will force it to end the session on the web server that it is connected to?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured