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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:33:33+00:00 2026-06-17T07:33:33+00:00

I Have this class to demonstrate my problem: class Program { static List<FileInfo> _foundFiles;

  • 0

I Have this class to demonstrate my problem:

class Program
{
    static List<FileInfo> _foundFiles;
    static int _numberPadding = 0;
    static Thread newThread;

    static void Main(string[] args)
    {
        _foundFiles = new List<FileInfo>();

        _shouldStop = false;
        newThread = new Thread(new ThreadStart(StartSearch));
        newThread.Start();

        newThread.Join();

        Console.WriteLine("Finished");
        Console.ReadKey();
    }

    static volatile bool _shouldStop;

    static void StartSearch()
    {
        IterateFileSystemNon(new DirectoryInfo(@"D:\OLD Melman\Music Backup\iTunes 28-06-11\Music"));
    }

    static void IterateFileSystemNon(DirectoryInfo folder)
    {
        string pad = CreatePadding();

        Console.WriteLine("{0} Directory: {1}", pad, folder.Name);

        foreach (var dir in folder.GetDirectories())
            IterateFileSystemNon(dir);

        pad = CreatePadding();

        foreach (var file in folder.GetFiles())
        {
            if (file.Extension.Contains("mp3"))
            {
                _foundFiles.Add(file);

                Console.WriteLine("{0} File: {1}", pad, file.Name);
            }
        }

        _numberPadding = _numberPadding - 6;
    }

    static string CreatePadding()
    {
        _numberPadding = _numberPadding + 3;

        var stringRepOfPadding = new StringBuilder(_numberPadding);
        for (int i = 0; i < _numberPadding; i++)
        {
            stringRepOfPadding.Append(" ");
        }
        return stringRepOfPadding.ToString();
    }
}

I have theses questions:

  1. This works in a console app, but this doesn’t work in a WindowsFormsApplication, it just goes straight to the Join statement, why is this?
  2. If the Join statement as Microsoft puts it “is suppose to block the current thread until the spawned thread has finished”. Surely this defeats the object of multi-threading? In my WindowsFormsApplication, I don’t want to block any thread while this thread is running it’s task.
  3. Why do I need the Join. Surely when my Iteration void has completed iterating then the thread should just terminate?!
  4. How inside the new thread do I indicate it has finished so that it will close the thread?
  • 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-17T07:33:34+00:00Added an answer on June 17, 2026 at 7:33 am
    1. With Join you will hang UI thread. Use BackgroundWorker component to search files in background thread.
    2. Do not start thread and join to it. This is same as doing all work sequentially in one thread, because nothing is executed asynchronously in this case.
    3. You don’t need Join (see p2). And using Join in UI thread is always bad idea.
    4. You don’t need to indicate that thread is finished to close thread. Thread will exit when your thread delegate will finish execution. See Multithreading: Terminating Threads
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class: class OriginalClass { string FirstItem; List<string> ListOfSecondItems; } I want
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have created this simple android Activity to demonstrate my problem. I just want
To demonstrate my problem, consider this simple program that does not compile: #include <boost/noncopyable.hpp>
I have this class: Class B { private String D; private String E; }
I have this class file call SMSHelper.cs First I just wanted to know is
I have this class in which I run a for loop 10 times. This
I have this class which i would like to map: public class Contract {
i have this class public class Image { public string url { get; set;
i have this class called MemoryManager, it is supposed to implement a simple smart

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.