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

  • SEARCH
  • Home
  • 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 1002677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:51:50+00:00 2026-05-16T07:51:50+00:00

hi this is my multi thread codes it works fine using System; using System.Collections.Generic;

  • 0

hi this is my multi thread codes it works fine

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;

namespace searchIpAdresses
{
    public partial class frmSearchIpRange : Form
    {
        public frmSearchIpRange()
        {
            InitializeComponent();
        }

        int intStartIp, intEndIp;

        private void frmSearchIpRange_Load(object sender, EventArgs e)
        {
            startIp.Text = "0.0.0.0";
            endIp.Text = "0.1.0.0";
            nudThreads.Value = 1;
        }

        private bool calcIpAddressRange()
        {
            intStartIp = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(IPAddress.Parse(startIp.Text).GetAddressBytes(), 0));
            intEndIp = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(IPAddress.Parse(endIp.Text).GetAddressBytes(), 0));
            if (intStartIp>intEndIp)
            {
                MessageBox.Show("End Ip must be bigger than Begin Ip!");
                return false;
            }
            else
            {
                return true;
            }
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            if (calcIpAddressRange())
            {
                int threadCount = Convert.ToInt32(nudThreads.Value);
                Thread[] threads = new Thread[threadCount];              

                for (int i = 0; i < threadCount; i++)
                {
                    threads[i] = new Thread(new ThreadStart(getPerformance));                  
                    threads[i].Name = string.Format(i.ToString());
                }

                foreach (Thread t in threads)
                {
                    t.Start();
                }

                //for (int i = 0; i < nudThreads.Value; i++)
                //{
                //    if (threads[i].IsAlive)
                //        threads[i].Abort();
                //}
            }

        }

        private void getPerformance()//int sampleStartIp, int sampleEndIp
        {
            if (calcIpAddressRange())
            {
                lbAddress.Items.Clear();
                progressBar1.Maximum = intEndIp - intStartIp;
                int i;
                for (i = intStartIp; i < intEndIp; i++)
                {
                    string ipAddress = new IPAddress(BitConverter.GetBytes(IPAddress.NetworkToHostOrder(i))).ToString();

                    progressBar1.Value++;
                    lbAddress.Items.Add(ipAddress);
                }
                MessageBox.Show(i.ToString() + " addresses added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                progressBar1.Value = 0;
            }
        }
    }
}

but I want to split jobs in getPerformance function. so I have to use it like

threads[i] = new Thread(new ThreadStart(getPerformance(sampleStart, sampleEnd)))

etc in this case visual studio gives me “Method name expected” error. what is the solution ?

edit : I tried this but I couldnt adapted it to array format work @Henk Holterman

Thread[] threads = new Thread[threadCount];              

                for (int i = 0; i < threadCount; i++)
                {
                    //threads[i] = new Thread(new ThreadStart(getPerformance));                  
                    threads[i].Name = string.Format(i.ToString());

                    Thread t = new Thread(() => getPerformance(intStartIp, intEndIp));
                }

                foreach (Thread t in threads)
                {
                    t.Start();
                }
  • 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-05-16T07:51:51+00:00Added an answer on May 16, 2026 at 7:51 am

    1) You probably should be using the Threadpool or Tasks (Fx4).

    2) When you can use delegates lamba’a (.NET 3 and later)

      int a=1, b=2;
      Thread t = new Thread(() => Worker(a, b));
    

    For older versions you can use ParameterizedThreadStart and a helper object to hold Start and End.


    Edit to adapt your loop:

    for (int i = 0; i < threadCount; i++)
    {
       // some code to update intStartIp, intEndIp 
    
       //threads[i] = new Thread(new ThreadStart(getPerformance));                  
       threads[i] = new Thread(() => getPerformance(intStartIp, intEndIp));
       threads[i].Name = string.Format(i.ToString());   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My .bashrc looks something like this... export PERL5LIB=/tools/perl/Linux/${PLAT}/lib/perl5/5.10.0/${PLAT}-thread-multi export PERL5LIB=${PERL5LIB}:/tools/perl/Linux/${PLAT}/lib/perl5/5.10.0 function dev { export
I am having problems posting this multi checkbox data with ajax. <?php foreach($_SESSION['contacts'] as
I need to solve a locking problem for this scenario: A multi CPU system.
I'm using CoreData in a multi-threaded iOS-app, and everything seems to work fine -
I'm writing a multi-threaded server application in Java. Everything works fine , but there's
I have got a multi-threaded app that process a very large data file. Works
I'm having some problems attempting to create a multi-threaded Server. Everything works fine until
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)
I want to use redis cache store (using redis-store gem). It works fine locally
I am doing dual core optimization by multi-threading, and it works like this: If

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.