Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:25:42+00:00 2026-06-02T09:25:42+00:00

I have win form with one button start and when i click on it

  • 0

I have win form with one button “start” and when i click on it start reading .txt file row by row and post requests to a server.
My question is –
How can i make when i click on “start” to read 50 rows from file then stop and wait for another click on “start”.
Is threading the only possible solution here?
This is my button:

private void btnStart_Click(object sender, EventArgs e)
    {
        List<string> List = LoadFromFile("FILE");
        int dialogid = 0;
        foreach (string g in List)
        {
            dialogid++;
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("number", g);
            parameters.Add("dialogid", dialogid.ToString());

            if (InvokeService(this.tbWebServiceURL.Text, parameters) == false)
            {
                MessageBox.Show("ERROR!", "ERROR");
                return;
            }
        }

And here is my post request:

private bool InvokeService(string ServiceURL, Dictionary<string, string> parameters)
    {          
        try
        {           
            string data = "";
            int cnt = 0;

            byte[] dataStream = Encoding.UTF8.GetBytes(data);
            WebRequest webRequest = WebRequest.Create("URL");
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentLength = dataStream.Length;

            foreach (KeyValuePair<string, string> kvk in parameters)
            {
                webRequest.Headers.Add(kvk.Key, kvk.Value);
            }

            WebResponse response = webRequest.GetResponse();
            Stream dataStreamResponse = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStreamResponse);
            string responseFromServer = reader.ReadToEnd();
            Console.WriteLine(responseFromServer);
            reader.Close();
            dataStreamResponse.Close();
            response.Close();

Most important here is not read whole file with one click on “start”. Must wait for another “start”. Read 50 rows and wait to click on ‘start” to read second 50 rows.
Hope now is more clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:25:45+00:00Added an answer on June 2, 2026 at 9:25 am

    BackgroundWorker outline – not tested:

            private void button1_Click(object sender, EventArgs e)
            {
                if (fileReader == null) fileReader = new StreamReader("File");
                string thisLine;
                netJob bwClass = new netJob(this.tbWebServiceURL.Text);
                for (int i = 0; i < 50; i++)
                {
                    thisLine = fileReader.ReadLine();
                    if(thisLine=="")break;
                    dialogid++;
                    Dictionary<string, string> newDict = new Dictionary<string, string>();
                    newDict.Add("number", thisLine);
                    newDict.Add("dialogid", dialogid.ToString());
                    bwClass.Fparams.Add(newDict);
                }
                backgroundWorker1.RunWorkerAsync(bwClass);
            }
    
    
    
        class netJob
        {
            private string FURL;
            public List< Dictionary<string, string> > Fparams;
            private Dictionary<string, string> FthisParam;
            public string errorMess;
            public string responseFromServer;
            public List<string> responsesFromServer;
            public netJob(String URL)
            {
                FURL = URL;
                Fparams= new List< Dictionary<string, string> >();
                responsesFromServer=new List<string>();
                errorMess = "";
            }
            public void run()
            {
                foreach (Dictionary<string, string> thisDict in Fparams)
                {
                    InvokeService(FURL, thisDict);
                    if (errorMess == "") responsesFromServer.Add(responseFromServer);
                    else
                    {
                        responsesFromServer.Add(errorMess);
                    }
    
                }
            }
    
            private bool InvokeService(string ServiceURL, Dictionary<string, string> parameters)
            {
                try
                {
                    string data = "";
                    byte[] dataStream = Encoding.UTF8.GetBytes(data);
                    WebRequest webRequest = WebRequest.Create("URL");
                    webRequest.Method = "POST";
                    webRequest.ContentType = "application/x-www-form-urlencoded";
                    webRequest.ContentLength = dataStream.Length;
    
                    foreach (KeyValuePair<string, string> kvk in parameters)
                    {
                        webRequest.Headers.Add(kvk.Key, kvk.Value);
                    }
    
                    WebResponse response = webRequest.GetResponse();
                    Stream dataStreamResponse = response.GetResponseStream();
                    StreamReader reader = new StreamReader(dataStreamResponse);
                    responseFromServer = reader.ReadToEnd();
                    reader.Close();
                    dataStreamResponse.Close();
                    response.Close();
                }
                catch (Exception e)
                {
                    errorMess = e.Message;
                }
            }
        }
    }
    
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            {
                netJob thisJob = e.Argument as netJob;
                thisJob.run();
            }
    
    
            private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                    netJob thisJob = e.Result as netJob;
                    foreach (string thisResponse in thisJob.responsesFromServer)
                    {
                        Console.WriteLine(thisResponse);
                    }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a win form that creates a site in IIS7. One function needs
Scenario I have a C# Win Forms App, where the Main Form contains a
Updated to be clear. Step One: I have a XML file that I want
I have problem with win application when more then one network cards is plugged
I have a win form, on which there are several radionbuttons and labels and
I have to work with a Project made by another developer. A project Win-Form
I have created a win form solution in C#. The solution has three projects,
I am working on vb.net win form. My task is display the file names
In a win form application, I have an array of threads which are started
i have a TLF in a form in one of my sites. from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.