How to wait for Notes client to startup with OLE NotesUIWorkspace - C#

I’m trying to “spawn” a Notes client “New Memo” screen from within my C# program with certain fields filled in. I was able to figure out how to get it done with Notes32 except when the Notes client is not already up and running.

Does anyone know how one can wait for the client to come all the way up or at least check the running status of the client to make sure the workspace is available.

Here is a simple code to demonstrate this:

using System;

using System.Collections.Generic;

using System.Text;

using System.Reflection;

using lotus;

namespace NotesStub

{

class Program

{

    static void Main(string[] args)

    {



        Type NotesUIWorkspaceType = Type.GetTypeFromProgID("Notes.NotesUIWorkspace");

        object workspace = Activator.CreateInstance(NotesUIWorkspaceType);



        //Find e-mail DB via NotesSession

        Type NotesSessionType = Type.GetTypeFromProgID("Notes.NotesSession");

        object session = Activator.CreateInstance(NotesSessionType);



        object[] Arguments0 =

        {

            (System.Object) "", 

            (System.Object) "",

        };

        object db = NotesSessionType.InvokeMember("GetDatabase", BindingFlags.InvokeMethod, null, session, Arguments0);

        NotesSessionType.InvokeMember("OpenMail", BindingFlags.InvokeMethod, null, db, null);

        object srvr = NotesSessionType.InvokeMember("Server", BindingFlags.GetProperty, null, db, null);

        object path = NotesSessionType.InvokeMember("FilePath", BindingFlags.GetProperty, null, db, null);



        //access UIDB

        object[] Arguments1 =

        {

            (System.Object) srvr,

            (System.Object) path,

        };

        //****** Throws and exception here if Notes is not up

        object uidb = NotesUIWorkspaceType.InvokeMember("OpenDatabase", BindingFlags.InvokeMethod, null, workspace, Arguments1);

        

        //compose new e-mail

        object[] Arguments2 =

        {

            (System.Object) "",

            (System.Object) "", 

            (System.Object) "MEMO",

        };

        object Doc = NotesUIWorkspaceType.InvokeMember("ComposeDocument", BindingFlags.InvokeMethod, null, workspace, Arguments2);



        //fill in subject line

        object[] Arguments3 =

        {

            (System.Object) "Subject",

            (System.Object) "This is a test",

        };

        NotesUIWorkspaceType.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, Doc, Arguments3);



    }

}

}