Task<T> and Task in Func delegate

Viewed 1381

I want to cleanup some of my code. I have overloaded method. Can I somehow simplyfy this code and invoke one method in another ? Cant figure out how to do this.

private async Task<T> DecorateWithWaitScreen<T>(Func<Task<T>> action)
{
    SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
    try
    {
        return await action();
        
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
        throw;
    }
    finally
    {
        SplashScreenManager.CloseForm(false);
    }
}

private async Task DecorateWithWaitScreen(Func<Task> action)
{
    SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
    try
    {
        await action();
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
        throw;
    }
    finally
    {
        SplashScreenManager.CloseForm(false);
    }
}
1 Answers
Related