Window Service in C#.net

Posted by Ruchir under C# on 6/1/2009 | Views : 2525 | Status : [Member] | Replies : 5
is it possible to run window service in C#.net without Timer ???

i can not understand , how the service is continuously running in the background?

for E.g. i made one service which update one field value in database table based on condition?

for e.g expiration of status based on date comparing(Todays Date)...

now such condition is not happend regularly...so 1st time i started service ..it works...but now (without rebooting PC) i manually add the date in database which satisfied that condition (entering OLD Date), then it won't work...

but if i use timer Deligate - ElapsedEventHandler , which call that checking condition function on every 10 seconds , then it works.......

so the purpose of window services is to run continuously in background and update databse as per condition......but without timer it is not possible...but i don't want 2 use timer here..

if u have any solutions, then plz give me..

thank you

Ruchir..




Responses

Posted by: Vuyiswamb on: 6/1/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Afternoon Ruchir

Ruchir wrote :
is it possible to run window service in C#.net without Timer ???
Yes it is Possible. You can use Threads


Ruchir wrote :
i can not understand , how the service is continuously running in the background?
Some people use Timers , but you can use Threads.



Ruchir wrote :
for e.g expiration of status based on date comparing(Todays Date)...

That is another Example, A Serice will always run and execute the task as long as the tast is true. Its like a loop that will always run as long as the condition is true.





Ruchir wrote :
but if i use timer Deligate - ElapsedEventHandler , which call that checking condition function on every 10 seconds , then it works.......


I have once Written an Article for Dotnetfunda, the Article is about a Service that kills the Process on your PC(Task Manager) every 5 seconds. i have made an example of the process using a notepad. You can do you database work instead of killing the Process.
Here is the Link for the article

http://www.dotnetfunda.com/articles/article191.aspx


Thank you for Posting at Dotnetfunda

Vuyiswa Maseko




Thank you for posting at Dotnetfunda
[Administrator]

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ruchir on: 6/1/2009 [Member] Starter

Up
0
Down
thanks Vuyiswa Maseko ,

i tried it, and its really works, thanks 4 that, but here we r using infinite loop
While(true)
{

}
so due to this , is it possible that performance may decrease ?
b'coz every 5 seconds this function(which check the database value) is called.....
so it may arises performance issue, am i right?

Ruchir..

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/1/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Ruchir

Dont Worry about Perfomance, it will not cause any problems.

Thank you for Posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ruchir on: 6/1/2009 [Member] Starter

Up
0
Down
ok , thank you very much Mr. Maseko.......

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/2/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You are Welcome

Thank you again for Posting at .NETFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response