7 Replies Latest reply on Jun 28, 2012 6:38 PM by dhollebeek

    Launching Website From Toolbar Button vs. Add-in Form

    helgesonc

      Hello,

       

      In my ProcessBook Toolbar Add-In I've run into a strange quirk regarding opening a browser window with a URL.  When I click a button on a windows form that's part of the add-in, the website opens just fine.  When I click a toolbar button (code in Connect.vb) whose only purpose is to open the website it works fine, but right after the website launches, ProcessBook throws an error:

       

      5314.webURLerror.png

       

      The code used in both places is identical:

       

       

       
      System.Diagnostics.Process.Start(webURL)
      

       

       

      Is there a workaround for this?  Why would launching a URL from the toolbar cause an error even though it was successful? 

       

      To try to make a workaround, I wrote a quick "Friend Shared" function on the windows form (where the code didn't error) to be called by both buttons, but that didn't work either - the toolbar button still caused the error and the windows form button did not.

       

      More info:  this is ProcessBook 3.2.

       

      Sincerely,
      Caleb

        • Re: Launching Website From Toolbar Button vs. Add-in Form
          mhamel

          @Caleb: I have reproduced your problem and I come up with some explanations. This error is thrown by PI ProcessBook when an exception is raised within a method of your Connect class which has no Try and Catch block defined. PI ProcessBook version 3.2 intercepts this message and returns it through a MessagBox dialog box. This behavior has been corrected/changed in version 3.3 to not show this MessageBox dialog box.

           

          To fix your problem you should create a Try and Catch block around the call of the Process.Start method.

           

          During the opening of the Web browser, a possible exception might have happened and have been returned to the calling application.

           

          Let me know if that answered your question.

            • Re: Launching Website From Toolbar Button vs. Add-in Form
              helgesonc

              Mathieu,

               

              Thanks for your response.  Unfortunately I can't get that to work.  Even with the toolbar button configuration as simple as

               

               

               
              AddHandler theBUTTONS(i).Click, AddressOf LaunchWebsite
              theBUTTONS(i).LoadFaceResource(nAppInstance, 103) 
              
              

               

               

              and

               

               

               
              Public Sub LaunchWebsite(ByVal commandBarButton As PBObjLib.PBCommandBarButton, ByRef cancel As Boolean)
                  Try
                      System.Diagnostics.Process.Start(webURL)
                  Catch ex As Exception
                      MessageBox.Show("Error!")
                  End Try
              End Sub
              

               that error still happens.

               

              What's a little odd is that (when in debug mode) if I put a breakpoint in the function and step through it, the error never appears as long as the breakpoint is on or before the Process.Start call.  Without the breakpoint, or putting the breakpoint anywhere after the Process.Start call, the error still shows up.

               

              Again - whether or not the ProcessBook error shows up, the website is always opened as expected.  The code in the Catch section never executes.

               

              Sincerely,
              Caleb

               

               

                • Re: Launching Website From Toolbar Button vs. Add-in Form
                  mhamel

                  @Caleb: Can you try to define a blank Catch leg instead? I suspect that if the error is raised from an unmanaged component it cannot be "translated" as a .NET exception and be raised correctly.

                   

                  You could try to write your method like illustrated below.

                   
                  Public Sub LaunchWebsite(ByVal commandBarButton As PBObjLib.PBCommandBarButton, ByRef cancel As Boolean)
                       Try
                           System.Diagnostics.Process.Start(webURL)
                       Catch
                           Dim i As Integer = 1
                       End Try
                   End Sub
                  

                  I was also wondering which .NET Framework are you using for this add-in?