CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    29

    [RESOLVED] Threads listing and general use

    I need to add thread to various things in an application I am working on and I have a bit of difficulty with the architecture and control of the threads.

    I will have a few questions, all on threads, lets start simple

    I have a main form which needs to spawn a second form when we click a button but I need to still be able to use the parent form.
    I have something like.
    Code:
      private void button4_Click(object sender, EventArgs e)
            {
                Thread threadErrorPanel = new Thread(new ThreadStart(ErrorPanelStart));
                threadErrorPanel.Start();
                
            }
            private void ErrorPanelStart()
            {
                ErrorPanel fm2 = new ErrorPanel();
                fm2.ShowDialog();
             }
    It works fine, the two problems are:
    a. If I click on the button again it lanches a 3rd form etc..
    -- How can I check if a thread is already running ?

    b. if I close the Main form the 2nd form is still running
    -- How can I make main close all the threads that have been started ?

    c. How can I list all the threads launched from my application?
    Do I have to create a hashtable and populate it with my threads as I start them ? If so how can I maintain the table when a thread abnormally aborts ?

    Thanks

  2. #2
    Join Date
    May 2006
    Posts
    306

    Re: Threads listing and general use

    You would probably have to have a list designated for threads, then on application exit -> loop through the list and close all threads.

  3. #3
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Threads listing and general use

    by default threads are forground and will not be closed if you exit the application you need set IsBackground property of the threads to ture then if you exit the application they all be ceased to exist.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  4. #4
    Join Date
    Dec 2008
    Posts
    29

    Re: Threads listing and general use

    Thanks for answers, I made it keeping the thread in a list.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured