المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Windows Service Application: Will not execute separate class



C# Programming
06-29-2009, 08:51 PM
Hi,

I would like to turn one of the projects on this site into a service application - (the project "Capturing Minimized Window's: A Kid's Trick). I have followed a tutorial on how to build a service application and have inserted the classes into my application. However, it does not seem to execute these classes.

I do know that the application works because I have used the same code in an application I have built, so I do not understand why it will not work when I put it into a service application. Maybe I need to do something special with the classes?


private void OnElapsedTime(object source, ElapsedEventArgs e)
{
AddToFile(DateTime.Now + " Another entry");//Adds "Another Entry" to a text file so I can tell the timer loop is running

this.listBoxSnap.Items.Clear(); // Clears the list box
this.pictureBoxSnap.Image = null;
this.pictureBoxSnap2.Image = null;

//name space MinimizeCapture, class is WindowSnap
//In my normal application this line works great, adds the names of all the windows on my screen to a listbox
this.listBoxSnap.Items.AddRange(MinimizeCapture.WindowSnap.GetAllWindows(false, false).ToArray());

//The number of windows this application captures should be output to the text file, I keep getting "0" meaning the listbox has
//no items and the class isn't working
AddToFile(listBoxSnap.Items.Count.ToString());
}



My text files shows how the service starts/stops, shows the "Add to File" line and also shows a count of "0" for the listbox count.

I have researched Service Applications and have come across "Installer Classes" but I do not understand how to use them after having read up on them, nor do I understand if that is the problem? Do I need to call the class a certain way, can I not just simply "Insert a class" into this application like I would any other project?

Any help would be greatly appreciated.

Thank you.