1

Closed

CheckForNewerVersion

description

For my app I wanted to let the user know if they had the latest version and if not let them update. So I changed the check for new version to be an Action instead of just action so that when it returned I could decide what to show them.


public static void CheckForNewVersion(string uri, Action action)
{
CheckForNewVersion(uri, (n) => { if (n == true) action.Invoke(); });
}

public static void CheckForNewVersion(string uri, Action action)
{
....
}

private static void DoWebRequest(string uri, Version appVersion, Action action)
{
....
try
{
    Version currentVersion;

    if (Version.TryParse(response, out currentVersion))
    {
        if (action != null)
        {
            logger.Write("NOTE: version check of application. v{0} vs. v{1}.", appVersion, currentVersion);

            try
            {
                action(appVersion < currentVersion);
            }
            catch (Exception ex)
            {
                logger.Write("Failed to run action! {0}.", ex.Message);
            }
        }
    }
}
catch
{
}
....
}


Might be worth adding to the source here.
Closed Dec 1, 2012 at 3:26 AM by southernsun
Implemented.

comments