VB.NET: running the method only once during the life of the application

I am making a library type application that needs to scan an entire computer when it starts up for the first time. Never again. How can i do this?

I will use the SQL database to store data. So, I can easily make a table there and save the flag and check it on the first start, but is there any other way? Any native support for this in VB.NET?

+3
source share
5 answers

I found a better way to use appsettings.

+2
source

Use

Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun

or

My.Application.Deployment.IsFirstRun

Edit:

See this article for more information .

+6

. , VB.NET, > ( ), , . , .

Public Sub MethodToRunOnlyOnce()
    ' this flag will maintain its value between method calls '
    ' in the same session '
    Static methodAlreadyRun As Boolean = MethodHasBeenRun()

    If methodAlreadyRun Then
        Exit Sub
    End If

    Try
        ' ... code ... '
    Finally
        MethodToSetDatabaseFlag()
        methodAlreadyRun = True
    End Try
End Sub

Private Sub MethodToSetDatabaseFlag()
    ' code here to set Db flag '
End Sub

Private Function MethodHasBeenRun() As Boolean
    ' code here to check Db flag '
End Function
+1

You can always save this flag in an XML file or in the registry so that it is on the PC. If you store it in a database and there are several copies of this program on different computers, you will have to identify them in the database in some way, whereas if you track it locally, you do not need to worry about it.

+1
source

Source: https://habr.com/ru/post/1732186/


All Articles