tags:

views:

36

answers:

1

I writing (or trying to) an app in c# .Net 4 all is working but two functions that make calls to the Internet are very slow the first time they are called!

XDocument xmlDoc = XDocument.Load(@"http://somedomain/somefile.xml");

this takes around 15-20 seconds the first time an about 1 the next!

I'm also using WebRequest in another place to do an HTTP POST and I have the same issue when I hit that code!

I assume it's the time taken to load and initialise the assemblies!?

Any way to preload them? or a better way to access the net?

A: 

There are workaround for this in both server and client.

If you are sure that the time is taken by the server to generate the XML, put an HTTPHandler in the server and use Output Caching to the XML.

In client side, you invoke a Thread and call the XDocument.Load to load the file in the thread while you do your rest of the loading. Once the data is loaded properly use a CallBack, an Event to ensure that the object can be accessed.

abhishek
hi thanks, this all client side the XML on the server is in a static file.all the data on the client is ready and the use press a button to select the required action on of which may require the retrieval of the xml and another the HTTP Post to a server. given the above cinario how would go about what you are suggesting, sorry I quite new to c#!
Adrian
I have found the delay is due to the time it takes to find the proxy!adding <system.net> <defaultProxy enabled="false" useDefaultCredentials="false" > <proxy/> <bypasslist/> <module/> </defaultProxy> </system.net>removes the delay But how can i do this in code?
Adrian