Use Case
| • | You want to launch the viewer application and/or ensure the viewer is running so you can connect to the automation service. |
Sample Code
using System.Diagnostics;
using System.IO;
internal static class AutomationHelper
{
public static void StartViewer()
{
const string processName = "ClearCanvas.Desktop.Executable";
const string viewerProcessPath = @"C:\Program Files\ClearCanvas\ClearCanvas Workstation";
Process[] viewerProcesses = Process.GetProcessesByName(processName);
if (viewerProcesses == null || viewerProcesses.Length == 0)
{
string executable = Path.Combine(viewerProcessPath, processName) + ".exe";
ProcessStartInfo startInfo = new ProcessStartInfo(executable, "");
startInfo.WorkingDirectory = viewerProcessPath;
Process viewerProcess = Process.Start(startInfo);
if (viewerProcess == null)
MessageBox.Show("Failed to start the viewer process.");
}
}
}
Remarks
The sample code above checks to see if the viewer process is already running, and if it is, does nothing. If the process is not running, it will be started. This method can be executed as many times as you like and only one instance of the viewer will ever be launched.
Examples in Code Base
| • | ClearCanvas.ImageViewer.DesktopServices.Automation.TestClient.csproj (C# project) |