好基本C#的WebRequest到PHP腳本執行INSERT語句的問題
/// <summary>
/// Sends the process.
/// </summary>
/// <param name="MD5">The M d5.</param>
/// <param name="procName">Name of the proc.</param>
/// <param name="procLoc">The proc loc.</param>
public void SendProcess(string MD5, string procName, string procLoc)
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://localhost/EDAC//SubmitProc.php ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "MD5=" + MD5 + "&procName=" + procName + "&procLoc=" + procLoc + "&userID=" + _userID;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
}
該功能被稱爲一個循環
Process[] currentProcess = Process.GetProcesses();
foreach (var process in currentProcess)
{
var isContained = false;
foreach (var heldProcess in _processlist)
{
if (heldProcess.Id == process.Id)
{
isContained = true;
}
}
if (!(isContained))
{
try
{
_processLocs.Add(process.MainModule.FileName);
_processlist.Add(process);
_tw.WriteLine(process.ProcessName);
_tw.WriteLine(process.MainModule.FileName);
var md5 = GetMD5HashFromFile(process.MainModule.FileName);
_tw.WriteLine(md5);
SendProcess(md5, process.ProcessName, process.MainModule.FileName);
}
catch (Win32Exception ex)
{
}
}
}
基本上這個方法是好的我的本地主機上只是沒有Web服務器上,現在這種方法顯然不是空閒的,因爲當程序第一次加載時,你會在半秒內發送大約30個連接請求和消息,它基本上鎖定了,可能是因爲沒有連接。
那麼這樣做的正確方法是什麼?我一直在尋找一種方式來獲得一個循環往那個等待服務器已準備好採取更多的數據,或者是它可能發送的所有對象和處理是成插入PHP端
它不會被任何人使用,但它會是,它的測試反作弊應用程序,非常感謝:) – lee 2010-09-12 15:30:07