CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2008
    Posts
    61

    Question How to keep track of background threads?

    I have two threads, one UI thread and one Background thread..

    I want to keep a track of the background thread so that I may kill my UI thread (a tray icon) when the background thread has finished...

    Please review my code for more details..

    Code:
    class Program
        {
            static void Main(string[] args)
            {
                Thread[] threads = new Thread[2];
                threads[0] = new Thread(new ThreadStart(UIMethod));
                threads[1] = new Thread(new ThreadStart(BackGroundMethod));
                threads[0].SetApartmentState(ApartmentState.STA);
                threads[0].Start();
                threads[1].Start();
                /*What should I write here so that I know when BackGroundMethod has finished, I can kill my system tray icon*/
            }
            public static void UIMethod()
            {
                /*Generate the system tray*/
                   Tray obj = new Tray();	
    	obj.GenerateTrayIcon();
    	Application.Run();
            }
            public static void BackGroundMethod()
            {
                /*Do some heavy background work..*/
            }
        }



    Any suggestions with some code would be highly appreciated..

    Thanks.
    Last edited by somu0915; May 27th, 2008 at 08:07 AM.

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