473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Web Proxy Problem

Thank you in advance for any help you can provide. I am writing a C# program
that checks to see if the URLs of favorites/bookmarks are still good. The
problem I am having is that while the program is checking the URLs, the text in
a label on the current window will not update until after all URLs are checked.
I think the Form/Window is frozen while the http requests are occuring. Does
anyone know of a way I can update the Form in real time while checking the
URLs. A code snippet is below:

using System;
using System.Net;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Threading;

namespace URLChecker
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class URLClass
{
private OutputForm OutForm;

public URLClass()
{
FileInfo[] fileNames; // FileInfo array

OutForm = new OutputForm();

OutForm.Show();
OutForm.Focus();
//GetFavoritesDirectory();
fileNames = GetFileNames();
CheckURL(fileNames);
}

public void GetFavoritesDirectory()
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\Documents and Settings\\Owner" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
// Insert code to read the stream here.
myStream.Close();
}
}
}

public void CheckURL(FileInfo[] sURL)
{
WebRequest wrGETURL;

WebProxy myProxy = new WebProxy("myproxy",80);
myProxy.BypassProxyOnLocal = true;

Stream objStream;

foreach (FileInfo fiTemp in sURL)
{
if(fiTemp != null)
{
string currentURL = null;

// ToDo: write code to extract the URL from fiTemp.Name
currentURL = ExtractURL(fiTemp.Name);
wrGETURL = WebRequest.Create(currentURL);
wrGETURL.Proxy = WebProxy.GetDefaultProxy();

// Try to make a get request to the site
// If the get request was unsuccessful
// Tell the user the URL is bad and exit the program

// ============================== The below line is what will not update
in real time
OutForm.CheckingW
ebSiteLabel.Text = fiTemp.Name;

try
{
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);

//Console.ReadLine();
//Console.WriteLine("{0} is good", fiTemp.Name);
}

catch(Exception q)
{
objStream = null;
//Console.WriteLine("{0} is bad", fiTemp.Name);
//System.Console.WriteLine(q);
}
}
}
//Console.WriteLine("Finished checking");
}

// Return file names that end in .url
public FileInfo[] GetFileNames()
{
String tempString = null;
String tempURL = null;
int j=0;

FileInfo[] FI = new FileInfo[250];
// Create a reference to the current directory.
DirectoryInfo di = new DirectoryInfo("c:\\Documents and
Settings\\Owner\\Favorites");

// Create an array representing the files in the current directory.
FileInfo[] tempFI = di.GetFiles();

// Remove all filenames that do not end in .url or
// their url does not start with http://
foreach(FileInfo i in tempFI)
{
tempString = i.ToString();

if(tempString.EndsWith(".url"))
{
tempURL = ExtractURL(tempString);
if(tempURL.StartsWith("http://"))
{
FI[j]=i;
j++;
}
}
}

return FI; // Return the array of file names
}

// Open the file named "fileString" and extract the
// URL from the second line after chopping off "BASEURL="
// The file is in the following format:
// [Default]
// BASEURL=http.....
// [Internet Shortcut]
// URL=http.....
// Modified=......
//
// Note: The above can only be viewed using 'edit' from DOS
// If you use Notepad you will get a copy of the cached web page
public string ExtractURL(string fileString)
{
int x = 0;
string[] input = new string[100];
char[] trimChars = new char[8] {'B', 'A', 'S', 'E', 'U', 'R', 'L', '='};

StreamReader sr = File.OpenText("c:\\Documents and
Settings\\Owner\\Favorites\\" + fileString);

while((input[x] = sr.ReadLine()) != null) {
x++;
}
sr.Close();

// Remove "BASEURL=" from the start of the string
input[1]=input[1].TrimStart(trimChars);
return input[1];
}
}

}

Jul 21 '05 #1
1 2911
Lentdave67t wrote:
Thank you in advance for any help you can provide. I am writing a C#
program that checks to see if the URLs of favorites/bookmarks are
still good. The problem I am having is that while the program is
checking the URLs, the text in a label on the current window will not
update until after all URLs are checked. I think the Form/Window is
frozen while the http requests are occuring. Does anyone know of a
way I can update the Form in real time while checking the URLs.


You have to introduce a worker thread handles the HTTP stuff. The easiest
approach IMHO is to use asynchronous I/O, so instead of calling
GetResponse(), you call BeginGetResposne()/EndGetResponse(). See
http://msdn.microsoft.com/library/de...ponsetopic.asp

Cheers,
--
Joerg Jooss
jo*********@gmx.net

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kevin Sagon | last post by:
I am running a J2EE Web App under Tomcat 4.1 with Apache 2.0 proxying requests. Everything is configured and working appropriately however I ran into a problem after configuring J2EE Form...
6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
3
by: Soul | last post by:
Hi, I am learning to code a WinForm application which will need to access a Web Service outside the University network. Our University require us to go through a proxy in order to access the...
5
by: Benne Smith | last post by:
Hi, I have three enviroments; a development, a testing and a production enviroment. I'm making a big application (.exe), which uses alot of different webservices. I don't use the webservices...
3
by: Wild Wind | last post by:
Hello all, I apologise in advance for the long windedness of this post, but I feel that if I am going to get any solution to this problem, it is important that I present as much information...
9
by: Codex Twin | last post by:
I am re-sending this in the hope that it might illicit a response. I have a corporate client who forces their workstations to get the proxy server details using an automatic proxy discovery script....
2
by: rcp | last post by:
Hi all, I've read all posts from all existing threads and none of them worked to solve my problem, although its exactly the same. I'll try to explain my case and see if a kind soul could help me...
2
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the...
2
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with...
4
by: Jon | last post by:
I wrote a VS 2005 C# express programme that accesses a web service. It works fine when there's a direct connection to the internet, but on two different PCs with internet access via a proxy, I get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.