Calling a function in class A from a thread in class B [C#]
<p>Now with all the WaitOne and ManualResetEvent stuff working (thanks!) I've got one last problem, that is running a function in Class A from a thread which is part of Class B - again allow me to illustrate ...</p>

<p>Look at the function "DoIt(obejct param)" within class A, this needs to be called by class A (as shown) as well as by the thread in class B (as shown) ... how can this be accomplished? Would some form of delegates help?</p>

<pre><code>class A
{
private ManualResetEvent manualResetEvent;
int counter = 0;

public A()
    {
    manualResetEvent = new ManualResetEvent(false);
    B child = new B(manualResetEvent);

    if (manualResetEvent.WaitOne(1000, false))
        {
        ... do the work I was waiting on ...
        }

    ... do more work ...
    // Call the function DoIt from within A //
    DoIt(param)

    }

    // This is the function that needs to be called from A and thread in B
    void DoIt(object param)
    {
    counter++;
    ... do something with param with is local to A ...
    }

};


Class B
{
private ManualResetEvent manualResetEvent;

public B(ManualResetEvent mre)
    {
    manualResetEvent = mre;
    Thread childThread = new Thread(new ThreadStart(Manage));
    childThread.IsBackground = true;
    childThread.Name = "NamedPipe Manager";
    childThread.Start();

    private void Manage()
        {
        ... do some work ...
        ... call some functions ...

        // Calling the function from Class A, obviouslly doesn't work as-is
        DoIt(param);

        manualResetEvent.Set();

        ... do more work ...
        ... call more functions ...
        }
    }
};
</code></pre>

<p>Any one have any suggestions on how I can accomplish this task in a thread-safe manner?
Any help would be much appreciated.
Thanks,</p>
