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 8093599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:08+00:00 2026-06-05T20:32:08+00:00

How to write multithread windows application that runs a program in given number of

  • 0

How to write multithread windows application that runs a program in given number of threads and show results of time taken from each thread. I tried to create it but I can see that my program shows incorrect result that means when I increase the number of threads , time taken by each thread increases as well (as shown by message box). following is my code:

private static void StartMultithread(long recordsToProcess, string connectionString, string stagingTableName, bool tableLockEnabled, bool transactionEnabled, int batchSize, bool userMultipleDatabases, bool userMultipleTables, bool userMultipleUsers, int bulkInsertTimeout)
 {
 Dictionary<string, Thread> threadPool = new Dictionary<string, Thread>();
 for (int i = 0; i < threadCount; i++)
 {
     Thread thread = new Thread(new ParameterizedThreadStart(delegate(object tid)
     {
         int ii = (int)tid;
         Core.BulkInsert bulkInsert1 = new Core.BulkInsert();
         string result1 = bulkInsert1.Insert(recordsToProcess, connectionString, stagingTableName, tableLockEnabled, transactionEnabled, batchSize, bulkInsertTimeout);
         MessageBox.Show (result1);
     }));

     thread.Name = i.ToString();
     threadPool.Add(thread.Name, thread);
 }

 for (int i = 0; i < threadCount; i++)
 {
     Thread thread = threadPool[i.ToString()];
     thread.IsBackground = true;
     thread.Start(i);
 }

 for (int i = 0; i < threadCount; i++)
 {
     Thread thread = threadPool[i.ToString()];
     thread.Join();
 }
}

As a result when I give threadCount = 1 , time taken is 0.8 sec.
When it is 2 , time taken by both threads is approx 1.2 sec each.
when it is 3 , time taken by them individually is approx 1.7 sec.

bulkinsert1.Insert inserts the records to database , for each thread I am passing different tables (so that table lock should not be bottleneck for insertion)

I want that all thread takes minimum time , I suppose it should be 0.8 sec as taken when threadCount is given 1.

I am new to threading , please correct me if I am wrong anywhere

  • 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-05T20:32:09+00:00Added an answer on June 5, 2026 at 8:32 pm

    I’m not sure how you’re timing things as it’s not apparent from the code provided.

    However, assuming bulkInsert1.Insert is an IO intensive operation (meaning your threads mostly wait for an IO operation to complete), it is normal for completion times to increase as you increase the number of threads. You have more threads, but they are using some shared resources (e.g. MB bus, network card, a remote database, etc.). For example, if it takes 0.8s for the database to process an insert operation, it is normal for it to take longer to process two or more simultaneous connections doing the same thing– especially if those queries happen to block each other for some reason. Consequently, the completion times of your threads increase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write a c++ windows application (A), that uses LogonUser, LoadUserProfile and ImpersonateLoggedOnUser to
I need to write a MultiThreaded Java Application that will be used to load
that's what I have: a Windows Service C# multithreaded the service uses a Read-Write-Lock
I'm preparing to write a multithread network application. At the moment I'm wondering what's
I am trying to write a multithread program in Java where a server listens
I'm trying to use openmp to multithread a loop through std::set. When I write
Write a program to determine whether a computer is big-endian or little-endian. bool endianness()
write a script that takes two optional boolean arguments,--verbose‚ and ‚--live, and two required
I write programs used internally by our company. I've created several support DLLs that
I write applications for various platforms, but chiefly OS X and Windows. On both,

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.