dcsimg
Results 1 to 3 of 3

Thread: Fun Deployment Question!

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    Fun Deployment Question!

    Well, this code was fun for me to work on so I hope it's also fun for you to help me with

    People can be running my click-once application while I am updating it. So I added code to check for an update and if there is one a little red label appears on our main form which the user can click and update. The check for an update happens every 20 seconds because all the grids on the main form were already refreshing their data every 20 seconds.

    I got this code from here

    I modified it like so:
    Code:
            private bool IsNewVersionAvailable()
            {
    
                UpdateCheckInfo info = null;
    
                if (ApplicationDeployment.IsNetworkDeployed)
                {
                    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
    
                    try
                    {
                        info = ad.CheckForDetailedUpdate();
    
                    }
                    //catch (DeploymentDownloadException dde)
                    //{
                    //    MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
                    //    return;
                    //}
                    //catch (InvalidDeploymentException ide)
                    //{
                    //    MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
                    //    return;
                    //}
                    //catch (InvalidOperationException ioe)
                    //{
                    //    MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
                    //    return;
                    //}
                    catch
                    {
    
                    }
    
                    return info.UpdateAvailable;
    
                    //if (info.UpdateAvailable)
                    //{
                    //    Boolean doUpdate = true;
    
                    //    if (!info.IsUpdateRequired)
                    //    {
                    //        DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
                    //        if (!(DialogResult.OK == dr))
                    //        {
                    //            doUpdate = false;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        // Display a message that the app MUST reboot. Display the minimum required version.
                    //        MessageBox.Show("This application has detected a mandatory update from your current " +
                    //            "version to version " + info.MinimumRequiredVersion.ToString() +
                    //            ". The application will now install the update and restart.",
                    //            "Update Available", MessageBoxButtons.OK,
                    //            MessageBoxIcon.Information);
                    //    }
    
                    //    if (doUpdate)
                    //    {
                    //        try
                    //        {
                    //            ad.Update();
                    //            MessageBox.Show("The application has been upgraded, and will now restart.");
                    //            Application.Restart();
                    //        }
                    //        catch (DeploymentDownloadException dde)
                    //        {
                    //            MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
                    //            return;
                    //        }
                    //    }
                    //}
                }
    
                return false;
                
            }
    When IsNewVersionAvailable() returns true, the label gets turned on so user can get the new version.

    A user, who left the application running overnight to test a date refresh (that after midnight a date that's set to Today would roll over), came to work this morning to an exception in this routine that object reference wasn't set to an instance. So that has to be on either ad or info. I think. You will see that I commented out some of the Microsoft exception handling code (actually all of it) because 1. Why wouldn't a new version be able to be downloaded? 2. My application *is not* corrupt and 3. My application *is* ClickOnce. But maybe I am too confident because something happened.

    I will add some trouble-shooting code, but in general do you know what could happen to break this code? Since there was no exception-handling the user got the canned message to Quit or Continue, and Continue worked fine but then 20 seconds later she got it again. And so on, every 20 seconds!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    Re: Fun Deployment Question!

    This has taken a turn for the worse because I have discovered there is a "known" problem. The new error is "A privilege that the service requires to function properly does not exist in the service account configuration blah blah blah". Apparently , I am not the only developer to have this problem. One of my users reported it to me yesterday and I was like "how do you know that's in my application" (the messagebox didn't identify anything as the culprit) but it was followed up by an object reference/instance error which definitely is my code. When I googled the error message, I found this discussion

    I could also have a "low tech" way of checking for a new version as suggested as the workaround in that thread I cited, but like this. My app is a port of a VB6 application and what the programmer did there was in a database table called DMS1PendingRevision he writes the version number he just completed and if users are running an older version they can update. Every 30 seconds the application checks, because there is already a 30 second timer to refresh data. I thought the way I did it was way cooler and way less error prone (I'm sure I would forget to update the database each time I published because I release code several times a day). But not if it crashes my application.

    In my OP, where I say "I got this code from here"...why didn't Microsoft say there was a bug in the code they posted in "from here"?? (In all fairness to them, I am using VS 2015. I will see if this is perhaps fixed in a later version...).
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    Re: Fun Deployment Question!

    This is what I have decided to do even though the programmer of the VB6 code said "I'd still prefer the database option like VB6. It seems taht all of this code has been a headache since it went in".

    The headache he is referring to is that if the application is minimized and you happen to click to restore it while it's busy checking for a new version, it will beep at you. But since I've just dropped the interval from 30 seconds to an hour, I am expecting many less headaches.

    So what I am doing is catching the "privilege that the service..." error and at that point turning off the check for an update. I put up a label that says New Version Check Off. If they click it, I give them the text of the exception that caused turning it off. Normally, this label will appear and say New Version Available, and you click to get it.

    My rationale for simply turning the option off is that people usually close out of the app at the end of the day and the next morning when they start up, they will get a message that there's an update and can get it every morning. What I added her is a convenience to know there is an update during the day during normal business hours and it 's their option if they want to disrupt their work, get the new version, and restart.

    Any comments? I just don't want to do something an old-fashioned way if there's a new call that's more reliable. Even though it's not reliable because Microsoft wrote it
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width