Can I make asynchronous components appear synchronous?
<p>I'm currently trying to fix an initialization problem that stems from the assumption that all sub-components initialize synchronously.</p>

<p>The UI instantiates a class that has its own UI.  It looks something like this:</p>

<pre><code>ConfWizard cf = new ConfWizard();
cf.ShowDialog();
</code></pre>

<p>The trouble is that the ConfWizard class makes use of another class that initializes asynchronously but must be ready before ShowDialog is called for correct functioning.  The ConfWizard code looks something like:</p>

<pre><code>public ConfWizard()
{
    helper = new HelperClass
    helper.ReadyEvent += new HelperClass.ReadyEventHandler(this.helper_ReadyEvent)
    helper.StartUp();
    // Do more initialization using properties of hc
}

private helper_ReadyEvent()
{
    //HelperClass is ready to use
}
</code></pre>

<p>Since the properties of helper may not be set until just before the ReadyEvent is raised, the current constructor generally does not initialize correctly.  It may seem obvious to put the remaining initialization into helper_ReadyEvent but that would result in the constructor returning prior to the object being ready for use.  Since the classes using the ConfWizard object assume once the constructor returns the object is fully ready for use, returning prematurely is not desirable.</p>

<p>Unfortunately I can't change the HelperClass so somehow I need to mask its asynchronous behaviour so that the ConfWizard class can be used synchronously.</p>

<p>I tried using a ManualResetEvent object (calling Set in the event handler) but calls to WaitOne are blocking and thus the event isn't processed hanging the application.</p>

<p>Any ideas on how to achieve this in .NET1.1?</p>

<p>UPDATE - Aug 21, 2009<br />
I had some time to experiment today and here's what I found.</p>

<p>WaitOne - if given a large enough timeout will work every time simply by stalling the application.  Unfortunately that timeout needs to be at least 5 seconds (longer than I care to wait).  Without a timeout, it still hangs.  The event that calls set simply never happens.</p>

<p>Sleeping - same as WaitOne in that with a long enough timeout it will seem to work.</p>

<p>Threading - I don't want the UI to continue until the initialization is done because the behaviour of the UI is altered by the results of the initialization.  However, splitting the initialization of the HelperClass object into a separate thread and calling Thread.Join to pause the main thread works.</p>

<p>So the solution to the problem seems to be using multiple threads in the right fashion.</p>
