private System.ComponentModel.BackgroundWorker spawnBrowserBackgroundWorker;
void Initialize ( )
{
this.spawnBrowserBackgroundWorker = new System.ComponentModel.BackgroundWorker();
this.spawnBrowserBackgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.spawnBrowserBackgroundWorker_DoWork);
}
/// <summary>
/// BackgroundWorker.DoWork event handler.
/// Just spawn a process to handle the URL based on the system's file association.
/// </summary>
private void spawnBrowserBackgroundWorker_DoWork ( object sender, DoWorkEventArgs e )
{
String url = e.Argument as String;
if (url != null)
{
Process process = new Process();
process.StartInfo.FileName = "rundll32.exe";
process.StartInfo.Arguments = "url.dll,FileProtocolHandler " + url;
process.StartInfo.UseShellExecute = true;
process.Start();
}
}
public void SpawnURL ( string url )
{
//...
// Asynchronously spawn a browser as this may take
// several seconds.
// Use BackgroundWorker to avoid queueing with the thread pool
// and avoid delay with Control.BeginInvoke.
spawnBrowserBackgroundWorker.RunWorkerAsync(url);
}