Archive
Click-Once Deployment
Deployment is the process by which you distribute a finished application or component to be installed on other computers. In Visual Studio 2010, you can deploy applications or components by using either ClickOnce deployment or Windows Installer deployment technology.
ClickOnce is a specially designed for smart client applications. It is very easy to develop and maintain. Once in place lot of time can be saved to distribute the application to the end users and turns out to be a very low cost solution.
There are two ways in which you can introduce it to your applications.
- Automatic Updates
- Using Click-Once API
Automatic Updates
In Visual Studio project properties you will see the Publish tab, where you will get various options to configure automatic updates. Following is the snapshot which depicts the same.
ClickOnce API
For much more extensibility and to overcome the anomalies with Automatic Updates. We can use ClickOnce API. Following sample shows a class implementation which will handle auto updates. Using API you can make updates on-demand or force them on to users. Following implementation can be used for the same using “UpdateCompleted” event using which you can either forcefully restart the application or notify the user to notify about updates.
public class ApplicationDeploymentManager
{
static ApplicationDeploymentManager _applicationDeploymentManager = null;
Timer _updateCheckTimer = null;
ApplicationDeployment _currentApplicationDeployment = null;
public delegate void ApplicationUpdateHandler();
public event ApplicationUpdateHandler UpdateAvailable;
public event ApplicationUpdateHandler UpdateCompleted;
private ApplicationDeploymentManager()
{
try
{
_currentApplicationDeployment = ApplicationDeployment.CurrentDeployment; _currentApplicationDeployment.CheckForUpdateCompleted += new CheckForUpdateCompletedEventHandler(_currentApplicationDeployment_CheckForUpdateCompleted); _currentApplicationDeployment.UpdateCompleted += new AsyncCompletedEventHandler(_currentApplicationDeployment_UpdateCompleted);InitializeUpdateCheckTimer();
}
catch (Exception ex)
{
}
}
public static ApplicationDeploymentManager Instance
{
get
{
if (_applicationDeploymentManager == null)
return _applicationDeploymentManager = new ApplicationDeploymentManager();
return _applicationDeploymentManager;
}
}
public void InitializeUpdateCheckTimer()
{
_updateCheckTimer = new Timer(new TimerCallback(CheckForTaskboardUpdate), null, 0, 60000);
}
public void CheckForTaskboardUpdate(object state)
{
if (_currentApplicationDeployment != null)
_currentApplicationDeployment.CheckForUpdateAsync();
}
void _currentApplicationDeployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable)
{
try
{
_availableApplicationVersion = e.AvailableVersion.ToString();
_currentApplicationDeployment.UpdateAsync();
if (UpdateAvailable != null)
UpdateAvailable();
}
catch (Exception ex)
{
}
}
}
void _currentApplicationDeployment_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
{
if (UpdateCompleted != null)
UpdateCompleted();
}
}
}
Here is the video which has the demonstration for the same. http://windowsclient.net/learn/video.aspx?v=6879
