Click here to Skip to main content
15,901,205 members
Home / Discussions / C#
   

C#

 
GeneralRe: Web Services Applications Pin
Luc Pattyn11-Dec-09 14:08
sitebuilderLuc Pattyn11-Dec-09 14:08 
GeneralRe: Web Services Applications Pin
electriac11-Dec-09 14:15
electriac11-Dec-09 14:15 
GeneralRe: Web Services Applications Pin
Luc Pattyn11-Dec-09 14:24
sitebuilderLuc Pattyn11-Dec-09 14:24 
GeneralRe: Web Services Applications Pin
electriac11-Dec-09 14:34
electriac11-Dec-09 14:34 
GeneralRe: Web Services Applications Pin
Luc Pattyn11-Dec-09 14:49
sitebuilderLuc Pattyn11-Dec-09 14:49 
QuestionError: cannot convert from 'ref Scripting.Dictionary [c:\...\Interop.Scripting.dll]' to 'ref Scripting.Dictionary []' Pin
Wes Jones11-Dec-09 11:58
Wes Jones11-Dec-09 11:58 
AnswerRe: Error: cannot convert from 'ref Scripting.Dictionary [c:\...\Interop.Scripting.dll]' to 'ref Scripting.Dictionary []' Pin
Abhinav S11-Dec-09 22:45
Abhinav S11-Dec-09 22:45 
QuestionVisual Studio 2008 Windows Service - CPU process usage [modified] Pin
Tomb42111-Dec-09 10:56
Tomb42111-Dec-09 10:56 
I have a Visual Studio 2008 Windows Service application that is working wonderfully with 1 exception.

The CPU process shows 49 or 50 percent in Windows Task Manager. I'm sure it is because I have in a Continuous loop, but I'm not sure of the best way to adjust in a service because I do want it to check for files to process continually.

How can I modify to reduce CPU process usage?

Any and all advice welcomed.

Here is a code snippet :

public Service1()
{
    InitializeComponent();

    if (!System.Diagnostics.EventLog.SourceExists("AppNameLogSource"))
    {
        System.Diagnostics.EventLog.CreateEventSource("AppNameLogSource", "AppNameLog");
    }

    eventLog1.Source = "AppNameLogSource";
    eventLog1.Log = "AppNameLog";

}

// The main entry point for the process
static void Main()
{
    System.ServiceProcess.ServiceBase[] ServicesToRun;

    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new AppNameService.Service1() };

    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}

protected override void OnStart(string[] args)
{
    eventLog1.WriteEntry("AppName Service has started");

    var worker = new Thread(AppNameService);
    worker.Name = ("AppNameServiceWorker");
    worker.IsBackground = false;
    worker.Start();

}

protected override void OnStop()
{
    eventLog1.WriteEntry("AppName Service has stopped.");
}

protected override void OnContinue()
{

    eventLog1.WriteEntry("AppName Service is continuing and working.");

}


void AppNameService()
{

    string sRetVal;
    string sRetVal2;
    string sFileName;
    string sImportDir;
    string sTypeImportFile;
    int iInt1;
    int iInt2;

    Boolean bolContinueService = true;

    sWinDir = System.Environment.GetEnvironmentVariable("windir");

    sRetVal = Get_AppSettings((sWinDir + "\\AppNameServiceAppSettings.ini"));

    do
    {
        try
        {

        sRetVal = Get_AppNameServiceList((sWinDir + sAppNameServiceListName));

        Boolean bolCompareValue = false;
        bolCompareValue = CompareStrings(sRetVal, "Success");
        if (bolCompareValue == true)
        {
            iInt1 = 0;
            do
            {

                (Run of a Subroutine that looks and sees if there are files to process.
                 It will set the bolFilesToProcess = True if it finds any files
                 Or set the bolFilesToProcess = False if there are not.)


                if (bolFilesToProcess == true)
                {
                    iInt1 = iNumberOfINIs; //Force end of Loop because found first File to Process.
                }
            }
            while (iInt1 < iNumberOfINIs);


            if (bolFilesToProcess == true)
            {
                eventLog1.WriteEntry("Call AppName to process new files found.");

                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (System.Diagnostics.Process exeProcess = System.Diagnostics.Process.Start(@sApp2Executable, @"/r"))
                {
                    exeProcess.WaitForExit();
                }

                eventLog1.WriteEntry("AppName completed processing of files.");

            }
        }


        }

        catch (Exception ex)
        {
             bolContinueService = false;

             sErrorMessage = "Error in AppName Service Continuous process Loop. Error: " + ex.Message;

             eventLog1.WriteEntry(sErrorMessage, EventLogEntryType.Error);
        }
        finally
        {
            GC.Collect();
        }

    }

    while (bolContinueService == true);

    eventLog1.WriteEntry("ContinueService Process has stopped due to Internal Service Error. - AppNameService ");
}


modified on Saturday, December 12, 2009 7:47 AM

AnswerRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Luc Pattyn11-Dec-09 11:06
sitebuilderLuc Pattyn11-Dec-09 11:06 
GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42112-Dec-09 1:53
Tomb42112-Dec-09 1:53 
AnswerRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Luc Pattyn12-Dec-09 2:28
sitebuilderLuc Pattyn12-Dec-09 2:28 
GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42112-Dec-09 4:14
Tomb42112-Dec-09 4:14 
GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42114-Dec-09 2:31
Tomb42114-Dec-09 2:31 
QuestionListView in WPF Pin
Antonio JVS11-Dec-09 8:28
Antonio JVS11-Dec-09 8:28 
QuestionLoader Lock was detected [modified] Pin
Xelalem11-Dec-09 7:58
Xelalem11-Dec-09 7:58 
AnswerRe: Loader Lock was detected Pin
Saksida Bojan11-Dec-09 8:56
Saksida Bojan11-Dec-09 8:56 
QuestionInfo about casting Pin
Saksida Bojan11-Dec-09 7:55
Saksida Bojan11-Dec-09 7:55 
AnswerRe: Info about casting Pin
Andrew Rissing11-Dec-09 8:00
Andrew Rissing11-Dec-09 8:00 
GeneralRe: Info about casting Pin
Andrew Rissing11-Dec-09 8:03
Andrew Rissing11-Dec-09 8:03 
GeneralRe: Info about casting Pin
Saksida Bojan11-Dec-09 8:43
Saksida Bojan11-Dec-09 8:43 
GeneralRe: Info about casting Pin
harold aptroot11-Dec-09 9:03
harold aptroot11-Dec-09 9:03 
QuestionHow do I attach event handlers to a late-bound object (C#)? Pin
Hawks Talon11-Dec-09 6:52
Hawks Talon11-Dec-09 6:52 
AnswerRe: How do I attach event handlers to a late-bound object (C#)? Pin
Saksida Bojan11-Dec-09 7:03
Saksida Bojan11-Dec-09 7:03 
GeneralRe: How do I attach event handlers to a late-bound object (C#)? Pin
Hawks Talon11-Dec-09 7:35
Hawks Talon11-Dec-09 7:35 
QuestionWMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup Pin
Jacob Dixon11-Dec-09 5:52
Jacob Dixon11-Dec-09 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.