473,386 Members | 1,821 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,386 software developers and data experts.

Transactions in a Windows Service

Hi Experts

I've written a c# windows service which runs another program at certain
intervals. The other program may take upto 20 minutes to complete it's tasks.

My question is what happens to the other program if a user decides to
manually stop the service (or there was a power cut) when the tasks have not
fully completed?

Should I wrap the other program within a transaction?

Is this the best approach or am I making things over complicated?

Many thanks

Nov 24 '06 #1
4 1928
"jez123456" <je*******@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
Hi Experts

I've written a c# windows service which runs another program at certain
intervals. The other program may take upto 20 minutes to complete it's tasks.

My question is what happens to the other program if a user decides to
manually stop the service (or there was a power cut) when the tasks have not
fully completed?
Users should not be able to stop services, only administrators should have this privilege.
Should I wrap the other program within a transaction?
This is not what transactions are meant for, the "other" application should care about this
by means of transactions and restart points, but this highly depends on what kind of
application it is.

Willy.

Nov 24 '06 #2
Hi Willy

Thanks for the prompt reply. The "other" application sychronizes SQL Server
tables with SQL statement etc. so presumably would be an ideal candidate for
transactions.

Would it be worth passing the service state to the "other" program if it was
stopping?


"Willy Denoyette [MVP]" wrote:
"jez123456" <je*******@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
Hi Experts

I've written a c# windows service which runs another program at certain
intervals. The other program may take upto 20 minutes to complete it's tasks.

My question is what happens to the other program if a user decides to
manually stop the service (or there was a power cut) when the tasks have not
fully completed?

Users should not be able to stop services, only administrators should have this privilege.
Should I wrap the other program within a transaction?

This is not what transactions are meant for, the "other" application should care about this
by means of transactions and restart points, but this highly depends on what kind of
application it is.

Willy.

Nov 24 '06 #3
"jez123456" <je*******@discussions.microsoft.comwrote in message
news:35**********************************@microsof t.com...
Hi Willy

Thanks for the prompt reply. The "other" application sychronizes SQL Server
tables with SQL statement etc. so presumably would be an ideal candidate for
transactions.
Sure, but you still need restart points if you need to recover from application or system
crashes.
Would it be worth passing the service state to the "other" program if it was
stopping?
What problem would it solve? Why is it important for the spawned process to know the state
of it's parent?
Windows services are meant to run from boot to shutdown time, so, they should be designed to
be as robust as possible. Critical services should be designed such that are restart-able,
that is, they should use restart points, so that they can pick-up and continue after a crash
or planned stop. However, your service should not try to recover the spawned processes
activities, that's the task of the spawned process.
Willy.

Nov 24 '06 #4
I have worked on a similar problem before where I designed a Windows service
that hosted several virtual services. The following solution assumes that you
have access to the code of the other application.

1. Set a timer on the windows service.

2. Start the other process on a new thread (if it is already not running) on
the tick event.

3. When the service is stopped, call the Stop method on the other process.
Let the process shut itself down gracefully and notify the parent through a
callback. I prefer to use a "soft" shutdown, which means that I use a
configuration file to control this behaviour. There is a very small time
limit of shutdown behaviour when used thru the Service control manager.

4. The parent can wait a specified amount of time for the other process to
fininsh (again configurable via config file) and then shut itself down
gracefully. If the other process does not reply in the specified time, then
the parent can force a shutdown with a potential loss of data (kill the
thread). If you design the other process carefully, then this last resort can
be minimized.

And yes to avoid nasty surprises from events beyond your control, the other
process should be designed with a rollback mechanism (like transactions).
However the Windows service host should not care about that and all it should
be concerned with, is to notify the child process when it is shutting down.

Hope I have helped.
--
Good luck!

Shailen Sukul
Architect
(BSc MCTS, MCSD.Net MCSD MCAD)
Ashlen Consulting Service P/L
(http://www.ashlen.net.au)
"jez123456" wrote:
Hi Experts

I've written a c# windows service which runs another program at certain
intervals. The other program may take upto 20 minutes to complete it's tasks.

My question is what happens to the other program if a user decides to
manually stop the service (or there was a power cut) when the tasks have not
fully completed?

Should I wrap the other program within a transaction?

Is this the best approach or am I making things over complicated?

Many thanks
Nov 26 '06 #5

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

Similar topics

6
by: Shaun Stuart | last post by:
I've got a webpage that calls some stored procedures with input variables. The procedures return recordsets and also some output variables. We're trying to get the values of the output variables....
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
2
by: Adnan | last post by:
Hey Ppl, I'm developing an Online Auction Site using ASP.net and am experiencing a problem with Transactions in ADO.Net. When beginTrasaction() function is invoked from a specific connection,...
2
by: Antuane | last post by:
any one have any idea how transactions could be enabled in webservices. i.e., suppose i've got 2 methods - one to add a contact, & the other to set some miscellaneous details for the contact, in a...
5
by: Allan Ebdrup | last post by:
I'm using dotNet 2.0 and VS2005, I would like to have some code call several webservices that I have written that insert data into a DB (MSSQL 2000) inside a transaction. So that I can rollback if...
2
by: =?ISO-8859-1?B?QW5kcukgSORuc2Vs?= | last post by:
Hi, I am writing a library to access a web service and perform several transaction with this web service: class ErpInterfaceTransaction { private $erpinterface, $transactionid;
0
by: No Name | last post by:
Hello, I have few question for scenario where I have wpf/winform client(s) connecting to windows service (hosting WCF code) which in turn connects to (single) SQL Server. Transactions...
5
by: Eric Fortin | last post by:
I have a disconnected handheld device that I want to send the results of the day to a database through a web service (on an intranet) What's the best method to do this? XML? Tab...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.