Coffeehouse Post

Single Post Permalink

View Thread: Question on C# Threads
  • User profile image
    pavone

    So I'm completely new to C# Threading and I'm having some trouble understanding some things. Currently I have a program that does something like this:

    Thread someThread = null;
    
    void foo()
    {
       someThread = new Thread(goo);
       someThread.Start();
    
    }
    
    void goo()
    {
       ...
    }
    
    void bar()
    {
       someThread.Join(); // Null Reference Exception
    }

    I've made that sure that someThread.Start() is being called. I'm guessing it's being set to null after finishing, and it's finishing before I call Join. I'm not too sure how to deal with this, because there may be a chance that the thread is not yet finished, so I don't feel too good about removing the Join since it should be synchronous. Any ideas niners?

    Thanks in advance.  Smiley