Async Check for Domain Fullname With WPF and Caliburn.Micro I have a small WPF program built using Caliburn.Micro which checks Active Directory for a user with the current username of the logged-on user. I have a Bootstrapper method:

protected async override void OnStartup(object sender, StartupEventArgs e)
{
    await ShellViewModel.CollectFullnameAsync();
    DisplayRootViewFor&lt;ShellViewModel&gt;();
}


This starts the ShellViewModel and kicks off an async method to start looking for the currently logged on user on the domain

My ShellViewModel looks like this:

public ShellViewModel()
{
    Computername = EnvironmentHelpers.ComputerName;
    Fullname = _fullnameplaceholder;
}

public static async Task CollectFullnameAsync()
{
    _fullnameplaceholder = ADHelpers.GetFullADName();

    while(_fullnameplaceholder == "Failed" &amp;&amp; _attemptsToCollectFullName &lt; 5)
    {
        _attemptsToCollectFullName++;
        await Task.Delay(2000);
        _fullnameplaceholder = ADHelpers.GetFullADName();
    }
}


So my code is meant to:


Look for the user on the domain
Check 5 times for the user, waiting 2 seconds between each attempt.
Display the ShellView with either "Failed" or the Fullname returned from the domain


Can I please get some insight into how I am performing this task? Is this the correct way to do this or am I barking up the wrong tree?
I'll start off by saying I don't have Caliburn.Micro experience but do have other MVVM experience.  

I'm going to assume the ShellView is the shell for your entire application.  I don't know what other code that is running but I can tell you as a user I would not want to fire off your application and wait for over 10 seconds, because we are waiting for 10 seconds plus the time it takes for the other calls to come back, to be able to use the application.  Worst yet is even if the screen hasn't shown.  Then I'm likely to fire it off multiple times thinking it stuck or I didn't double click it.   

In general it's not best practice to do async void, so I would question why Task.Delay instead of Thread.Sleep since the delay is the only async code.   

If we are leaving it as async it should be wrapped in a try/catch otherwise if there is an exception you will need to handle it in Application.DispatcherUnhandledException or AppDomain.UnhandledException.  Which brings up a point if there is an exception I assume you want just Failed as the user name? 

Now to a different idea.  You could remove this from startup, or try once to get it in startup,  Then setup a timer to recheck if it failed.  The application state could be based on if it has a name yet or not.  For Example:  The user can start entering data but can't save it until we retrieved the AD user.  

If just want to wait until there is user name or not it still better to give the user an idea what's going on so they can see the application isn't just hung and that's it's checking network activity.  Create an initial view of just gather application information and part of that is gathering network user information.