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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:01:46+00:00 2026-05-23T23:01:46+00:00

In my code below I am taking files that are being dragged and dropped

  • 0

In my code below I am taking files that are being dragged and dropped onto a button on my form, and processing them with a thread. I want to be able to have each thread complete it’s operation before the foreach loop is continued and processes the next file.

I tried a

testthread().Join();

right after the

new Thread(()…

but it gets an error because it wants me to pass the same parameters that I pass to the testthread when I initially start the thread.

Can someone please show me the command and syntax I would use to accomplish the thread joining?

private void btnClick_DragDrop(object sender, DragEventArgs e)
{
    string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);

    string ButtonName = "TestButton"

    string[] files = new string[10];

    files = (string[])e.Data.GetData(DataFormats.FileDrop);


    foreach (string file in files)
    {
        FileInfo fileInfo = new FileInfo(file);

        Console.WriteLine("++  Filename: " + fileInfo.Name + "   Date of file: " + fileInfo.CreationTime + "   Type of file: " + fileInfo.Extension + "   Size of file: " + fileInfo.Length.ToString());

        string CleanFileName = System.Web.HttpUtility.UrlEncode(fileInfo.Name.ToString());

        //Start  thread
        try
        {
            Console.WriteLine("++ Calling testthread with these params: false, " + ButtonName + "," + CleanFileName + "," + file);

            new Thread(() => testthread(false, ButtonName, CleanFileName, file)).Start();

            testthread().Join(); //THIS DOES NOT WORK BECAUSE IT WANTS THE PARAMETERS THAT THE THREAD IS EXPECTING.  WHAT CAN I PUT HERE SO IT WAITS FOR THE THREAD TO FINISH BEFORE CONTINUING THE FOREACH LOOP ?
         }
         catch (Exception ipwse)
         {
         Console.WriteLine(ipwse.Message + " " + ipwse.StackTrace);
         }
     }
}
public void testthread(bool CalledfromPendingUploads, string ButtonName, string CleanFileName, string FilePath)
{
    //My Code to do the file processing that I want done.  I do not want multiple threads to run at once here.  I need the thread to complete, then the foreach loop to continue to the next file and then start another thread and wait, etc...
}
  • 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-23T23:01:47+00:00Added an answer on May 23, 2026 at 11:01 pm

    If you are doing things serially, why do you need separate threads at all?

    Thread t = new Thread(() => testthread(false, ButtonName, CleanFileName, file));
    t.Start();
    t.Join();
    

    Edit:

    Also it looks like you are executing your foreach loop on the UI thread – this will block the UI thread and is generally not a good thing to do for a long running operation. I’d suggest you move the looping code into a separate method that you execute on another thread, also get rid of the separate thread for each file processing.

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

Sidebar

Related Questions

The code below shows a sample that I've used recently to explain the different
The below code is from my other questions that I have asked here on
I've traced slugishness in my application to the bit of code that's being timed
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
Code below is working well as long as I have class ClassSameAssembly in same
The code below gives me this mysterious error, and i cannot fathom it. I
The code below works. But if I comment out the line Dim objRequest As
The code below gives an error: Property 'Int32 Key' is not defined for type
The code below is the code i am using. It works fine in thunderbird

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.