我在專案中使用 Process 啟動了一個exe程式該程式需要到資料庫中讀取資料,但在首次使用EF操作資料庫時會特別慢需要3-5分鐘的時間,但是如果人為的去點擊exe啟動程式就特別快。使用Process 啟動程式為什么會導致這個結果?
下面是我使用Process 啟動程式的代碼。
private static void Start(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists) return;
Process dataCenterProcess;
dataCenterProcess = new Process();
dataCenterProcess.StartInfo.FileName = fileInfo.FullName;
dataCenterProcess.StartInfo.RedirectStandardInput = true;
dataCenterProcess.StartInfo.RedirectStandardOutput = true;
dataCenterProcess.StartInfo.CreateNoWindow = true;
dataCenterProcess.StartInfo.UseShellExecute = false;
dataCenterProcess.StartInfo.WorkingDirectory = fileInfo.DirectoryName;
dataCenterProcess.Start();
}
uj5u.com熱心網友回復:
使用Process方式啟動程式,在第一次使用Ef后再次使用EF操作就會很快。ef操作部分應該沒有問題,因為手動啟動程式時根本不會出現這個問題uj5u.com熱心網友回復:
(⊙o⊙)… 我找到原因了,原因是 Process.StartInfo.RedirectStandardInput = true 與 Process.StartInfo.RedirectStandardOutput = true; 這兩句的問題。我將這其改為False后就不會再出現等待時間超長了.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/267621.html
標籤:C#
