From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

network connection unavailable - need graceful solution

Hi. I have a VB.net application which relies heavily on reading NV's from a remote location.  If the connection to the remote location is not available for some reason, I receive the following error message and the application fails to start:

"An unhandled exception of type 'System.InvalidOperationException' occurred in Zebra_GUI.exe

Additional information: An error occurred creating the form. See Exception.InnerException for details.  The error is: The network variable process was not found or is not responding"

The debugger is pointing to this subroutine when the error occurs:

    Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            ZebraGUI.TBox_Info.Text = System.DateTime.Now.ToString + ": Starting Application"
    End Sub

Is there any way get the application to launch but tell the user that NVs are not available. I tried to put a try/catch in the above subroutine, but since there is no main form (because the app has not started yet) there is no way to display a dialog.  Any suggestions?


0 Kudos
Message 1 of 5
(4,246 Views)
Hi Steve_InMA,

I think you are on the right track with the try/catch. Since the form hasn't been created yet, I suggest creating a global variable, startup_error, to store the message from the catch block. Then, when the form loads and there is a value in this variable, display the message to the user and close gracefully.

Regards,
0 Kudos
Message 2 of 5
(4,223 Views)
That worked.  I created a global var in class MyApplication and even though the main form failed to get created, I was able to catch the error and exit gracefully.  Thanks for the help.
0 Kudos
Message 3 of 5
(4,220 Views)
Well... it mostly worked.  It seems this solution works sometimes, but not all the time.  I am now getting the same error I got in my original post. I am not longer catching the error for some reason.  It looks like whether or not I catch the error is a function of exactly when in the application descides to first contact the NV engine.

I'm trying to come up with a relieable way to ensure that all exceptions that could be generated as a result of the network not being available are caught.

Is there any way for me to tell the NVDataSource not to even try to connect to the NVEngine unless there is a valid network connection? I see the control has a property called "AutoConnect" which is set to "true".  What does this do?

Thanks for your help,
-Steve


0 Kudos
Message 4 of 5
(4,154 Views)

Hello Steve,

What are you using as the catch parameter?  I am guessing that you are not catching a generic enough error so that when an exception is thrown if it is not the exact exception you are expecting it does not take action on it.  You could just use a FINALLY statement in order to guarantee that you exit gracefully no matter what the exception is but I would not recommend it because the exception could be something completely unrelated to a network connection failure and you would not be notified.

I recommend that you take a look at this document:

http://www.vbdotnetheaven.com/UploadFile/rajeshvs/dotnetException04162005022135AM/dotnetException.as...

Regards,
Ben M
Applications Engineer
National Instruments
0 Kudos
Message 5 of 5
(4,124 Views)