473,388 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to run the C# Console application as services?

Joe
Dear Friends,
How to run the C# Console application as services?
I have a console application.I want run this application as background
services.User don't want see the command propmt.
If anyone knows please let me know.

Thanks,
Joe
Nov 15 '05 #1
3 37947
You have to create a window service project, and copy the code you want to
run and place your code in the OnStart function. Example:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Remoting
{
public class MainService : System.ServiceProcess.ServiceBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(),
new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MainService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MainService
//
this.ServiceName = "Dion Backup Service";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
TcpChannel chan=new TcpChannel(8085);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(RemotingServer),"D
ionBackupServer",
WellKnownObjectMode.Singleton);
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your
service.
}
}
}

"Joe" <ra********@hotmail.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Dear Friends,
How to run the C# Console application as services?
I have a console application.I want run this application as background
services.User don't want see the command propmt.
If anyone knows please let me know.

Thanks,
Joe

Nov 15 '05 #2
Joe
Dear Dan Cimpoiesu,
Thanks for your reply.
The application is console apllication.How to disable the command prompt
through C# Program? But the application will run the backround
continuously.
If you know please let me know...

Thanks,
Joe

"Dan Cimpoiesu" <da**********@gmx.net> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
You have to create a window service project, and copy the code you want to
run and place your code in the OnStart function. Example:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Remoting
{
public class MainService : System.ServiceProcess.ServiceBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MainService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MainService
//
this.ServiceName = "Dion Backup Service";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
TcpChannel chan=new TcpChannel(8085);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(RemotingServer),"D ionBackupServer",
WellKnownObjectMode.Singleton);
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your
service.
}
}
}

"Joe" <ra********@hotmail.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Dear Friends,
How to run the C# Console application as services? I have a console application.I want run this application as background
services.User don't want see the command propmt.
If anyone knows please let me know.

Thanks,
Joe


Nov 15 '05 #3
You want to run a console app but not have it create a new console
window?

Either make it a service and run it thru' the services layer in
Windows or create a formless windows forms application.

I think the service is the better way to go.

"Joe" <ra********@hotmail.com> wrote in message news:<eG**************@TK2MSFTNGP09.phx.gbl>...
Dear Dan Cimpoiesu,
Thanks for your reply.
The application is console apllication.How to disable the command prompt
through C# Program? But the application will run the backround
continuously.
If you know please let me know...

Thanks,
Joe

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel Bass | last post by:
Forgive me if this is in the wrong place, I couldn't find a suitable .net services newsgroup to post in. I read in services that they are designed to have no UI, but I'd like to create one that...
1
by: Stephen Miller | last post by:
On my development machine (where the group 'Everyone' has full access to every directory), the following code successfully shells to a console application: Dim objShell As...
19
by: Jeff S | last post by:
Whenever I execute any Console commands (Console.WriteLine "yada yada yada"), the console does not appear. It doesn't even flash by. I want to be able to use Console commands. Any ideas? I'm...
7
by: | last post by:
Hi to everyone! I have an Apache Webserver running on Win2000. I try to start a console application an the server though PHP, with the functions exec() or passthru() but it doesn't work. The...
6
by: Krish | last post by:
I want to develop and application that run periodically in the server machine. Now Should I go for a windows service or just create a Console application and schedule it using the windows Task...
10
by: viashino | last post by:
Hi, I have written a Console Application that is doing different things, like checking the status of different network Hosts. I would like to implement a WebInterface to show such status, and...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.