473,402 Members | 2,061 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,402 software developers and data experts.

Problem Updating Form

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
2 1760
Hi LentDave

I would when it was my problem ask this question in the newsgroup.

microsoft.public.languages.csharp

Probably you can get there a good advice.

I hope this helps?

Cor
Jul 21 '05 #2
Lentdave67t <le*********@aol.comnospam> 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 need to check the URL in a different thread, noting that you should
only ever update the UI from the UI thread using Control.Invoke. The
preferred way of "running" a form is to use Application.Run(form) by
the way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

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

Similar topics

1
by: Sure | last post by:
Hello All, I want to update a form using the LWP & HTTP method. It was working fine when I am updating the values like this $ua = LWP::UserAgent->new; $url...
1
by: William Bradley | last post by:
At the moment I am having a problem with relationships and updating tables. The following is a production run. Table1 -- MainFormTable1 -- Basic Table Record Table2 ----SubFormTable2 --...
9
by: Víctor | last post by:
Hello, I'm filling a array of System.Diagnostic.Process by using GetProcesses() method. Due to a retard on this method, I do the call using a function and it passing like a delegate to one...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
6
by: Bernie Hunt | last post by:
I have a simple app that grabs records from a database and steps through them processing each record. I have three text fields on the form to give the user feedback on the progress. With each...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
8
by: chromis | last post by:
Hi, I'm writing a contacts section for a cms on a website, I've decided to write the section in OO code. So far I have my Contacts object and a page structure I would use for a procedural site. ...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.