Windows service taking up 99% of cpu usage
<p>I created a windows service but it is eating up 99 % or the cpu usage, is there something I should be calling in c# code once what needs to be done is done?</p>

<p>Like is there some sort of "idle" state so the service is still listening on a port but isn't eating up so much cpu usage?</p>

<p>edit</p>

<pre><code>    if (store_number.ToString().Length &gt;= 3)
    {

        store_no_Folder = store_number.ToString();
        try
        {
            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder))
            {
                logInfor.log("Creating: " + AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder);
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder);
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + archived);
                try
                {
                    addst.aaddStation(ecm_path + "\\stations.xml", store_no_Folder, ecm_path);
                }
                catch (Exception ss)
                {
                    logInfor.log(ss.ToString());
                }
            }
        }
        catch (Exception ds)
        {
            logInfor.log(ds.ToString());
        }
        if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + archived))
        {
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + archived);
        }
        try
        {
            doc.Save(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + archived + "\\" + dateTime + "_SO.xml");
            doc.Save(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + "\\" + dateTime + "SO.xml");
            logInfor.log("Saving SO.xml to designated folder: " + stored_xmls);
            string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder);
            for (int v = 0; v &lt; files.Count(); v++)
            {
                /*fileN = files[v];*/

                while (files[v].Contains("\\"))
                {
                    files[v] = (files[v].Substring(files[v].IndexOf('\\') + 1));
                }
                logInfor.log("Moving :" + AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder + "\\" + files[v] + " ---&gt; " + ecm_path + "\\Polling\\001" + store_no_Folder + "A\\OUT\\" + files[v]);
                addst.moveFiles(files[v], AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder, ecm_path + "\\Polling\\001" + store_no_Folder + "A\\OUT\\");
            }


            DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + locations + store_no_Folder);
            FileInfo[] Ffiles = di.GetFiles("*.xml")
                        .Where(p =&gt; p.Extension == ".xml").ToArray();
            foreach (FileInfo file in Ffiles)
                try
                {
                    logInfor.log("Deleting: " + file.ToString());
                    file.Attributes = FileAttributes.Normal;
                    File.Delete(file.FullName);
                }
                catch { }
            response = "Success";
        }
        catch (Exception arg)
        {
            response = "Failed";
            logInfor.log(arg.ToString());
        }

        logInfor.log("MESSAGE TO CLIENT CALLING METHOD: " + response);
        return response;
    }
    else
    {
        logInfor.log("Store number is out of range");
        response = "Store numbers have exceeded 999";
        return response;
    }
}
catch (Exception err)
{
    response = "Failed";
    logInfor.log(err.ToString());
    logInfor.log("MESSAGE TO CLIENT CALLING METHOD: " + response);
    return response;
</code></pre>

<p>I added the code.</p>