I am not a developer, but I understand the gist of what's happening. Either I need to use an asynchronous WebClient method or find a way to schedule the synchronous process better.
I copied a snippet of the code from my .cs file. Altogether there are 5 instances of the WebClient "client". I copied one of those for space sake.
My question is how would I code this asynchronously or is there a way to pause a synchronous instance of WebClient until previous instances are completed? I don't mind the delay, I just don't want the error message to pop up for the end user. Thanks to anyone who can help.
Code Snippet:
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net;
using System.IO;
using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
using proquest.Data;
using proquest.Entities;
public static WebClient client = new WebClient();
#endregion
///
public static double TreasuryValue(RateType type)
{
string xmlurl = "http://www.ustreas.gov/offices/domestic-finance/debt-management/interest-rate/yield.xml";
string filepath = HttpContext.Current.Server.MapPath("~/documents/yeild.xml");
if (File.Exists(filepath) && hoursSinceLastUpdate(filepath) > 24)
{
try
{
client.DownloadFile(xmlurl, filepath);
}
catch
{
}
}
else if (!File.Exists(filepath))
{
try
{
client.DownloadFile(xmlurl, filepath);
}
catch
{
}
}
Rodick WuPosted May 27, 2009, 1:58 AM
Rodick WuPosted May 27, 2009, 1:55 AM
joe bloePosted May 27, 2009, 1:20 AM
I left out a ). Forget my last post.
Your instructions seemed to work but I did get another error message.
Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.
Let me know what you think about this. Thanks again for your help. I am in a realy jam on this one.
Rodick WuPosted May 27, 2009, 12:38 AM
joe bloePosted May 27, 2009, 12:15 AM
1. The best overloaded method match for 'System.Net.WebClient.DownloadDataAsync(System.Uri, object)' has some invalid arguments
2. Argument '1': cannot convert from 'string' to 'System.Uri'
I guess I need to make a Uri object? How is that different than the string filepath?
Rodick WuPosted May 26, 2009, 10:29 PM