Hi,
I have developed a windows service application, by using multi threading, multiprocessing too.
Problem 1 : After service starts it takes the server into 100% CPU usage.
Problem 2 : If suppose i stop the service also, the process not stop, i can able to monitor that through task manager and resource monitor too..
Problem 3 : If no communication takes place with the service means also, the thread waiting in "Analysis Wait Chain"
Sample coding:
while ((true && serverEndData != "END"))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, 1);
ss = Encoding.ASCII.GetString(bytesFrom, 0, bytesFrom.Length);
fullRecDate = fullRecDate + ss.Trim();
getData[rec] = bytesFrom[0];
rec = rec + 1;
if (rec == 48)
{
rec = 0;
fullRecDate = DecryptTheData(getData);
Log(fullRecDate, "Main", "Smart");
string Str_DEcryptedData = string.Empty;
for (int lo = 0; lo < 48; lo++)
{
byte a3 = getData[lo];
int ij = Convert.ToInt32(a3);
Str_DEcryptedData = Str_DEcryptedData + " " + DecimalToBase(ij);
}
string smartid = fullRecDate.Substring(0, 3);
string hhid = fullRecDate.Substring(0, 3);
string sbsend = fullRecDate.Substring(0, 4);
if (smartid == "NSP")
{
try
{
string smartid = fullRecDate.Substring(5, 5);
Log(fullRecDate, "NSP", smartid);
string SPinfo2 = "";
SPinfo2 = "NSP" + DatePacket + SPinfo1;
SPinfo2 = SPinfo2.PadRight(48, '0');
Log(SPinfo2, "NSP ACK", Smartid);
byte[] encryptNsbData = EncryptTheDate(SBinfo2);
networkStream.Write(encryptNsbData, 0, encryptNsbData.Length);
}
catch (Exception err)
{
Log(err.Message, "New SP", "SP");
}
}
else
{
serverEndData = "END";
networkStream.Flush();
networkStream.Close(100);
Log("END", "Server Closed Connection ", "");
}
}
}
catch (Exception ex)
{
Log(ex.Message, "ReadDataFromDevice[Main Communication]", "Smart");
break;
}
}
}
catch
{
WriteLog("Application", "Smart", "Main Communication ", "Error");
}
}
I have verified that while communication starts one thread is opening after the communication ends, it was closing properly, i have monitored by using system log file as well as service log file too. While continuous monitor of 5 hours, not extra threads running and not makes CPU into high usage, while not monitoring for 8 -10 hours gap, while we checking there will be unclosed threads will be maintain in the "Analysis wait Chain".