.NET Framework Class Library
ApplicationDeployment..::.IsFirstRun Property

Gets a value indicating whether this is the first time this application has run on the client computer.

Namespace:  System.Deployment.Application
Assembly:  System.Deployment (in System.Deployment.dll)
Syntax

Visual Basic (Declaration)
Public ReadOnly Property IsFirstRun As Boolean
Visual Basic (Usage)
Dim instance As ApplicationDeployment
Dim value As Boolean

value = instance.IsFirstRun
C#
public bool IsFirstRun { get; }
Visual C++
public:
property bool IsFirstRun {
    bool get ();
}
JScript
public function get IsFirstRun () : boolean

Property Value

Type: System..::.Boolean
true if this version of the application has never run on the client computer before; otherwise, false.
Remarks

Use IsFirstRun to determine whether you need to perform any one-time initialization operations the first time your application runs.

Do not assume that a IsFirstRun setting of true indicates that this instance of an application is the first one to show its user interface to the user. Due to the way the system schedules processes, one instance of the application may have its IsFirstRun property set to true, but another instance may be the first to render on the screen. The value of this property is reset whenever the user upgrades from one version to the next. If you want to perform an operation only the very first time any version of the application is run, you will need to perform an additional test, such as checking for the existence of a file you created the first time, or storing a flag using Application Settings.

Examples

The following code example uses IsFirstRun to decide whether to check for an update to the file group HelpFiles. If one or more of the files have been updated, it calls DownloadFileGroup to obtain the new versions.

Visual Basic
Private Sub DownloadFileGroupSync(ByVal fileGroup As String)
    If (ApplicationDeployment.IsNetworkDeployed) Then
        Dim deployment As ApplicationDeployment = ApplicationDeployment.CurrentDeployment

        If (deployment.IsFirstRun) Then
            Try
                If (deployment.IsFileGroupDownloaded(fileGroup)) Then
                    deployment.DownloadFileGroup(fileGroup)
                End If
            Catch ioe As InvalidOperationException
                MessageBox.Show("This application is not a ClickOnce application. Error: " & ioe.Message)
                Exit Sub
            End Try

            DownloadStatus.Text = String.Format("Download of file group {0} complete.", fileGroup)
        End If
    End If
End Sub
C#
private void DownloadFileGroupSync(string fileGroup)
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;

        if (deployment.IsFirstRun)
        {
            try
            {
                if (deployment.IsFileGroupDownloaded(fileGroup))
                {
                    deployment.DownloadFileGroup(fileGroup);
                } 
            }
            catch (InvalidOperationException ioe)
            {
                MessageBox.Show("This application is not a ClickOnce application. Error: " + ioe.Message);
                return;
            }

            downloadStatus.Text = String.Format("Download of file group {0} complete.", fileGroup);
        }
    }            
}

.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker