Answer the question
In order to leave comments, you need to log in
Why does the program crash and close?
There is this code. The data from the textBox (which are in the form of id:auth) are sorted out and the request is sent
. I have about 9000 lines in the textBox. For some reason, at 80 - 120 lines the program hangs and goes down. How can I speed up the code and save the program from crashes.
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread myThread = new System.Threading.Thread(ProcessedF);
myThread.Start();
}
}
void ProcessedF()
{
int lineCount = textBox1.Lines.Length;
for (int i = 0; i < lineCount; i++)
{
string random_item = "109.234.155.197";
BeginInvoke(new MethodInvoker(() => label1.Text = (Convert.ToInt32(label1.Text) + 1).ToString()));
string str = textBox1.Lines[i].ToString();
string [] split = str.Split(new Char [] {':'});
string id = split[0];
string auth = split[1];
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://" + random_item + "/prison/universal.php?name=vk.com/mobileprison&method=renamehouse&key=" + auth + "&user=" + id);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
StreamReader myStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.GetEncoding(1251));
string text_check = myStreamReader.ReadToEnd();
Thread.Sleep(100);
}
Answer the question
In order to leave comments, you need to log in
Let's start with the fact that 9000 lines in a text box should not be. He's not meant for that. This must be uploaded to the file before processing. And it is better to read into an array, having already converted the data.
Secondly, what kind of 3.14zdets is this?
It was impossible to make a local variable with an increment inside the loop and output to the label? Or generally display the value of i in label1.Text (and set the offset from i, if necessary).
Where does text_check, which is the result of all this incomprehensible construction, go?
Why put sleep(100) if the design implies brute force on randomly generated ip addresses?
And finally, you need to close open connections behind you, as @maxaon already said .
Most likely, it is necessary to close the resource, after finishing working with it
, A is better to use the constructionusing
using (StreamReader myStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.GetEncoding(1251)))
{
//This allows you to do one Read operation.
Console.WriteLine(sr.ReadToEnd());
}
What does Visual Studio's built-in debugger tell you? All exceptions can be caught to find out exactly where it occurred and why. When hanging, you can click on the "Pause" button to determine on which line the program stalled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question