public void Start(string directoryPath, int port, Uri address)
{
if (_process != null)
{
throw new InvalidOperationException("The IISExpress process is already running.");
}
if (address != null)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(address);
var webResponse = (HttpWebResponse)request.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
return;
}
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}
var iisExpressPath = DetermineIisExpressPath();
var arguments = string.Format(CultureInfo.InvariantCulture, "/path:\"{0}\" /port:{1}", directoryPath, port);
var info = new ProcessStartInfo(iisExpressPath)
{
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = true,
LoadUserProfile = true,
CreateNoWindow = false,
UseShellExecute = false,
Arguments = arguments
};
var startThread = new Thread(() => StartIisExpress(info))
{
IsBackground = true
};
startThread.Start();
}