I have written the following function to check if my database is currently marked as being offline (for example, maintenance reasons):
I want this check to be done every X seconds while the App is currently open (and initiate at the startup of the app) so I figured I could add the required code to the application startup event: create a timer and background worker programatically, add the handlers and do the check via backgroundworker.runworkerasync() on the timer tick interval. Problem is, when returning the check, I want to close the app (I will probably incorporate a 15 minute delay before it closes if the app was already open when the DB was disabled). Application.Exit is not available, I assume since that method is a part of windows forms and this piece of code is not. How do I need to structure this check so that I can close the application completely (or disable upon startup)?
Code:
Public Function DBDisabledCheck(ByVal sender As Object, ByVal e As EventArgs)
Dim DBSettingAdapter As New BE_DataSetTableAdapters.tblDBSettingsTableAdapter
Dim DBSettings = DBSettingAdapter.GetData()
If DBSettings(0).DisableDatabase Then
Return "Database is currently disabled!" & vbNewLine & DBSettings(0).DisableReason
End If
Return "Online"
End Function