Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have created one ASP.net web application in visual studio 2010. Now I want to convert it into windows service. How can i achieve it.


I am very new to windows service. I want same functionality in my windows service as it is in my asp.net web application.

It haven't any UI.

I am briefing my web application here so according to that you can guide me how to do it in windows service.

Retrieving very Big image from IMAGE folder which resides in my web application according to certain condition.

Resize those image and store it into database.

Retrive resized images stored in database and store it into server folder called Large and again resize that image in 3 more different size and save into their three respective size folders called List, Mini,*Thumb* on server.

Now i want to build windows service with same functionality and it run on server after every 15 mins.

Hope now i am more clear. please help me in this regards.

my web application code is working fine. but i don't know where to put this code in my windows service as I am very new to windows service.

I tried to put that code onstart and also oncontinue method but at that time service was not allowed to start.
It gives error message."Windows could not start the MYWindowService service on local computer. Error 1053: service didn't respond to start or control request in timely fashion" this service can not start on your local machine."

Your help is really appreciated.

Thanks in advance.
Posted
Updated 13-Mar-13 5:16am
v3
Comments
ZurdoDev 12-Mar-13 9:18am    
Create a new windows service project. Copy any code that will work and rewrite any that won't. A windows service and a web app are 2 completely different things.
Member 9884645 12-Mar-13 10:02am    
Hi Thanks,

Connection string which i stored in web application web.config file.Working fine in web application but not working i windows service as it is not supporting System.Web.Configuration. Below is code to call in to windows service:

SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["b1"].ConnectionString);

not working also server.mappath() is also not working. so what to write their place?
ZurdoDev 12-Mar-13 10:10am    
I could be wrong but I believe System.ConfigurationManager IS available for a Windows Service. It means there will be an app.config instead of a web.config.
Member 9884645 12-Mar-13 10:18am    
i have also read the same. but how to get app.config file. I know to create web.config but not about app.config.

also there is System.configuration is available in web service. but it is not supporting configurationmanager.
ZurdoDev 12-Mar-13 10:24am    
App.config gets created when you create a new windows service project. If you do not have System.ConfigurationManager then add a reference to System.Configuration 3.0 version on the .Net tab of references.

Regarding error message : "this service can not start on your local machine."
Do you use Release build?. Sometimes, InstallUtil with the Debug build, gives this message. The Release build should work fine.
Ref: http://stackoverflow.com/a/7611641[^]

If you find this useful, rate it..
 
Share this answer
 
v2
public partial class MyNewService : ServiceBase
{
private DirectoryInfo imgDir;
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["b1"].ConnectionString);
string ImgName;
byte[] rImg;
public MyNewService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
//Here I am calling thread two ways i am doing but it gives same error
DoLongRunningStartupWork(); //or//
C#
(new Thread(() => DoLongRunningStartupWork()){IsBackground = true}) .Start();


}
void DoLongRunningStartupWork()
{
/// This part contains whole program code
}
 
Share this answer
 
Comments
Member 9884645 13-Mar-13 11:31am    
but still it is not working.. i need help
Richard C Bishop 13-Mar-13 11:33am    
You will want to use the "Improve Question" widget to add code to your thread or use the "Have a Question or Comment?" button to ask questions or add comments.
Member 9884645 13-Mar-13 11:35am    
oh i am really sorry i post it as a answer link...but do you have any idea about my issue?
Richard C Bishop 13-Mar-13 11:38am    
No worries, just a heads up so you don't get down voted or reported for abuse. I am not sure about your issue, I am not knowledgeable in that area.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900