473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;
using System.Threadin g;

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() ;
//GetFavoritesDir ectory();
fileNames = GetFileNames();
CheckURL(fileNa mes);
}

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

openFileDialog1 .InitialDirecto ry = "c:\\Docume nts and Settings\\Owner " ;
openFileDialog1 .Filter = "txt files (*.txt)|*.txt|A ll files (*.*)|*.*" ;
openFileDialog1 .FilterIndex = 2 ;
openFileDialog1 .RestoreDirecto ry = true ;

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

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

WebProxy myProxy = new WebProxy("mypro xy",80);
myProxy.BypassP roxyOnLocal = 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(fiTe mp.Name);
wrGETURL = WebRequest.Crea te(currentURL);
wrGETURL.Proxy = WebProxy.GetDef aultProxy();

// 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.Checkin gW
ebSiteLabel.Tex t = fiTemp.Name;

try
{
objStream = wrGETURL.GetRes ponse().GetResp onseStream();
StreamReader objReader = new StreamReader(ob jStream);

//Console.ReadLin e();
//Console.WriteLi ne("{0} is good", fiTemp.Name);
}

catch(Exception q)
{
objStream = null;
//Console.WriteLi ne("{0} is bad", fiTemp.Name);
//System.Console. WriteLine(q);
}
}
}
//Console.WriteLi ne("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(FileInf o i in tempFI)
{
tempString = i.ToString();

if(tempString.E ndsWith(".url") )
{
tempURL = ExtractURL(temp String);
if(tempURL.Star tsWith("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(stri ng 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(trim Chars);
return input[1];
}
}

}

Jul 21 '05 #1
1 2931
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 BeginGetResposn e()/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
3280
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 Authentication. I have a security constraint restricting access to the application so that when I attempt to access the app I am redirected to the login page. This works as expected both when accessing the application via the Apache proxy or hitting...
6
7923
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 Internet Explorer connection settings (proxy:8080). However, as soon as this setting is enabled, the remoting program running on their pc stops communicating with the server it sends data to. I've disabled proxy setting on the affected pc, rebooted...
3
2203
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 Internet. In addition, the proxy require us to authenticated before allow us to go through it. I have coded something like below (without changing anything other things): WebProxy proxyObject = new WebProxy("proxy.myUni.edu.au", 8080); //
5
3480
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 by adding a WebReference, since it does not allow me to keep state (cookiecontainer) or to specify functions on the classes (like if i want to override the ToString() function on a class from my webservice). So the only way i can see how i can get...
3
7763
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 that will be useful in diagnosing the problem. I have an application which calls a method of a web service that we host remotely. I have deployed the application to a
9
3445
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. Unfortunately, the .NET Framework does not support automatic proxy discovery scripts. See: http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;307220 The article above details that the way to workaround this is to edit the...
2
11422
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 out: I've a win32 service in C# on a client machine A, which accesses a WS (C#) on a server machine B (hosted on an IIS) Case 1: If I try to add the WSDL for the WS through VS2005, the 'Discovery
2
3477
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 HttpWebRequest object. Under normal circumstances I am able to use the webservice without any problems. But after using an HttpWebRequest object to make a call to a website all subsequent attempts to use the WebService will fail with a 401...
2
8158
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 407 Proxy Authentication Required. The same request through the old proxy succeeds. The same request to an HTTP address through the new proxy succeeds. Also, the request succeeds when forced to use Basic authentication but fails on NTLM.
4
4462
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 this exception: System.Net.WebException: The request failed with HTTP status 407: Proxy Authentication Required. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.