Hi! Yeah this seems really weird...Okay so its not updating any of the
text fields when I run it..it seems to be something to do with teh
while loop because when i comment out the while loop statements...the
first field...total counts does indeed update.
Any ideas?
public frmMainPage()
{
InitializeComponent();
}
private void quitToolStripMenuItem_Click(object sender,
EventArgs e)
{
Close();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
// Save Form Variables upon startclick
String Name = this.txtName.Text;
String Email = this.txtEmail.Text;
String Url = this.txtURL.Text;
string Comment = this.txtComment.Text;
int test = 0;
int ctr = 0;
string read = null;
string UrlGrab = null;
string postvar = "&newname=" + Name + "&newmail=" + Email
+ "&newloc=65&newurl=" + Url + "&newtext=" + Comment;
int TotalCount;
// Grab the URL totals out of the method
TotalCount = staticclass.Counter();
this.lblTotalCount.Text = Convert.ToString(TotalCount);
// Set progress bar maximums
progressBar1.Maximum = TotalCount;
// Open Stream
StreamReader tr = File.OpenText("url.txt");
// Start the loop
while (test == 0)
{
string textcount = Convert.ToString(ctr);
this.txtsucess.Text = textcount;
// Increment Counter Variable
ctr++;
// grab the first line from file
read = tr.ReadLine();
// assign value of grab to a string
UrlGrab = read;
// Set Post Variables Tuned For Achim Winkler
byte[] buffer =
Encoding.ASCII.GetBytes("&newname=" + Name + "&newmail=" + Email +
"&newloc=65&newurl=" + Url + "&newtext=" + Comment);
// Initialise HTTP Request and Method
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create(UrlGrab);
// Set WebRequest Method ie post or Get
WebReq.Method = "POST";
// Set the content typeof the form
WebReq.ContentType = "application/x-www-form-
urlencoded";
//The length of the buffer (postvars) is used as
contentlength.
WebReq.ContentLength = buffer.Length;
//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close.
Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle, we have no true
response yet!
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the
response
// Console.WriteLine(WebResp.StatusCode);
// Console.WriteLine(WebResp.Server);
//Now, we read the response (the string), and
output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new
StreamReader(Answer);
// Console.WriteLine(_Answer.ReadToEnd());
// Update Status Bar
progressBar1.Value = progressBar1.Value +
1;
// Update exit part of loop
if (read == "end")
{
test++;
}
}
// close the text readerstream
tr.Close();
[...]
Now the weird thing is that...when i run the app and it cycles through
some loops it never updates the values of those fields...even though
they havent thrown an error. So I checked if the loop was even running
by adding a messagebox.showpop up and sure enough its def running but
the text labels and textboxes dont change.
The two most common reasons this happens:
* The code is using the wrong form instance. Usually because the
programmer gets the form instance by calling "new Form1()" (where
"Form1" is the name of the form class). You need to make sure you are
using the instance that already exists, rather than creating a new one.
* The code is trying to access the form from the wrong thread.
This is much less common in .NET 2.0 and later, because when you are
running under the debugger you get an MDA exception telling you that
you're doing this, and that it's wrong to do so.
So, assuming you're using .NET 2.0 or later, I'd put my money on the
first option.
If neither apply, then you need to post a concise-but-complete example
of code that demonstrates your problem.
Pete