Click here to Skip to main content
15,894,094 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delegates from dynamically loaded DLL Pin
Tepel2-Feb-06 12:14
Tepel2-Feb-06 12:14 
Questionturn GUI program into service Pin
BlackDice2-Feb-06 11:29
BlackDice2-Feb-06 11:29 
AnswerRe: turn GUI program into service Pin
malharone2-Feb-06 11:39
malharone2-Feb-06 11:39 
GeneralRe: turn GUI program into service Pin
BlackDice2-Feb-06 11:54
BlackDice2-Feb-06 11:54 
GeneralRe: turn GUI program into service Pin
Colin Angus Mackay2-Feb-06 12:06
Colin Angus Mackay2-Feb-06 12:06 
GeneralRe: turn GUI program into service Pin
BlackDice2-Feb-06 12:14
BlackDice2-Feb-06 12:14 
GeneralRe: turn GUI program into service Pin
Colin Angus Mackay2-Feb-06 12:20
Colin Angus Mackay2-Feb-06 12:20 
GeneralRe: turn GUI program into service Pin
malharone2-Feb-06 12:11
malharone2-Feb-06 12:11 
Service and UI programs are meant for different things! Turning latter into the former is the real WTF!

Sample template for your service...

namespace MyNamespace<br />
{<br />
	public class MyService : System.ServiceProcess.ServiceBase<br />
	{<br />
		private System.Timers.Timer timer1;<br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public MyService()<br />
		{<br />
			InitializeComponent();<br />
		}<br />
<br />
		static void Main()<br />
		{<br />
			System.ServiceProcess.ServiceBase[] ServicesToRun;<br />
			ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyService() };<br />
			System.ServiceProcess.ServiceBase.Run(ServicesToRun);<br />
		}<br />
<br />
		private void InitializeComponent()<br />
		{<br />
			this.timer1 = new System.Timers.Timer();<br />
			((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();<br />
			this.timer1.Interval = 500;<br />
			this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);<br />
			this.ServiceName = "MyService";<br />
			((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();<br />
		}<br />
<br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
		protected override void OnStart(string[] args)<br />
		{<br />
			this.Initialize();<br />
		}<br />
<br />
		private void Initialize()<br />
		{<br />
			this.IsReady = true;<br />
			this.timer1.Start();<br />
			this.timer1.Enabled=true;<br />
		}<br />
		protected override void OnStop()<br />
		{<br />
			this.IsReady = false;<br />
			this.timer1.Stop();<br />
			this.timer1.Enabled=false;<br />
		}<br />
		public static DoSomethingAtSomeInterval(params object[] params)<br />
		{<br />
		}<br />
		private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
		{<br />
			if (!IsReady)<br />
			{<br />
				return;<br />
			}<br />
			else<br />
			{<br />
				IsReady = false;<br />
				try<br />
				{<br />
					//DoSomethingAtSomeInterval(...);<br />
				}<br />
				catch (Exception ex2)<br />
				{<br />
					//LogError(ex2);<br />
				}<br />
				IsReady = true;<br />
			}<br />
		}<br />
	}<br />
<br />
<br />
	[RunInstaller(true)]<br />
	public class ProjectInstaller : System.Configuration.Install.Installer<br />
	{<br />
		private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;<br />
		private System.ServiceProcess.ServiceInstaller serviceInstaller1;<br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public ProjectInstaller()<br />
		{<br />
			InitializeComponent();<br />
		}<br />
<br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if(components != null)<br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
<br />
		#region Component Designer generated code<br />
		private void InitializeComponent()<br />
		{<br />
			this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();<br />
			this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();<br />
			this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;<br />
			this.serviceProcessInstaller1.Password = null;<br />
			this.serviceProcessInstaller1.Username = null;<br />
			this.serviceInstaller1.DisplayName = "[%FunctionName%]Service";<br />
			this.serviceInstaller1.ServiceName = "[%FunctionName%]Service";<br />
			this.Installers.AddRange(new System.Configuration.Install.Installer[] {<br />
				this.serviceProcessInstaller1,<br />
				this.serviceInstaller1});<br />
<br />
		}<br />
		#endregion<br />
	}<br />
}

GeneralRe: turn GUI program into service Pin
BlackDice2-Feb-06 12:16
BlackDice2-Feb-06 12:16 
AnswerRe: turn GUI program into service Pin
Colin Angus Mackay2-Feb-06 12:02
Colin Angus Mackay2-Feb-06 12:02 
AnswerRe: turn GUI program into service Pin
Andy Brummer2-Feb-06 12:19
sitebuilderAndy Brummer2-Feb-06 12:19 
AnswerRe: turn GUI program into service Pin
bskirkman2-Feb-06 17:53
bskirkman2-Feb-06 17:53 
GeneralRe: turn GUI program into service Pin
bskirkman2-Feb-06 17:55
bskirkman2-Feb-06 17:55 
QuestionC# Class Inheritance Pin
LighthouseJ2-Feb-06 11:16
LighthouseJ2-Feb-06 11:16 
AnswerRe: C# Class Inheritance Pin
Guffa2-Feb-06 11:21
Guffa2-Feb-06 11:21 
GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:44
LighthouseJ2-Feb-06 11:44 
AnswerRe: C# Class Inheritance Pin
Guffa2-Feb-06 22:19
Guffa2-Feb-06 22:19 
GeneralRe: C# Class Inheritance Pin
LighthouseJ3-Feb-06 4:34
LighthouseJ3-Feb-06 4:34 
AnswerRe: C# Class Inheritance Pin
Ravi Bhavnani2-Feb-06 11:24
professionalRavi Bhavnani2-Feb-06 11:24 
GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:45
LighthouseJ2-Feb-06 11:45 
AnswerRe: C# Class Inheritance Pin
malharone2-Feb-06 11:37
malharone2-Feb-06 11:37 
GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:53
LighthouseJ2-Feb-06 11:53 
QuestionEDIT MENU + CUT, COPY, PASTE Pin
emran8342-Feb-06 11:08
emran8342-Feb-06 11:08 
AnswerRe: EDIT MENU + CUT, COPY, PASTE Pin
J4amieC2-Feb-06 23:08
J4amieC2-Feb-06 23:08 
GeneralRe: EDIT MENU + CUT, COPY, PASTE Pin
emran8343-Feb-06 17:20
emran8343-Feb-06 17:20 

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.