0
繼承的類我想在完成安裝後啓動的EXE http請求的時候,所以我寫了一個自定義的啓動條件像下面超時異常:的HttpRequest使得從System.Configuration.Install.Installer
[RunInstaller(true)]
public class InstallerClass : System.Configuration.Install.Installer
{
public InstallerClass() : base()
{
this.AfterInstall += new InstallEventHandler(InstallerClass_AfterInstall);
}
void InstallerClass_AfterInstall(object sender, InstallEventArgs e)
{
Directory.SetCurrentDirectory(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
ProcessStartInfo psi = new ProcessStartInfo(
Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) + "\\MyApp.exe");
psi.WorkingDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
psi.Verb = "runas";
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
.
.
. }
問題:MyApp.exe正在創建http請求以從服務器獲取一些數據。我得到超時異常每次如果MyApp.exe從這裏啓動。如果我單獨運行MyApp.exe,它會成功創建http請求而不會超時。下面是http請求的代碼:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Timeout = TimeOut;
request.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = WebRequest.DefaultWebProxy;
request.UseDefaultCredentials = true;
request.AllowAutoRedirect = true;
request.KeepAlive = false;
request.Method = "HEAD";
request.SendChunked = true;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
returnValue = response.StatusCode;
}
爲什麼會出現超時異常?我在哪裏做錯了?