Hi everyone,
I need to make a service that monitors a directory for changes in the files
contained within it. I have two questions:
1. I'm going to be using a FileSystemWatcher object to do the monitoring -
but do I need to somehow involve another thread to allow the service to do
other stuff as well, or is another thread created automatically when the
FileSystemMonitor object is created?
2. Because I'm creating a service, and not an application, do I need to
worry about threading at all? Is it possible that my service could try and
steal all the processors resources, or does the operating system
automatically give each service a shot of the processor such that I don't
have to worry about it?
Sorry, I'm a bit unkowledgeable in this area - I'm making an application for
my boss though and I don't want to arse it up! :-)
Thanks to nayone and everyone who can help
Kindest Regards
Simon 6 1339
Hi Simon,
Have a look as msdn.microsoft.com and use the as search keyword
"Remoting" that is what I think you are looking for.
Cor
> Have a look as msdn.microsoft.com and use the as search keyword "Remoting" that is what I think you are looking for.
Cor
Hi Cor,
I've already looked around msdn and I'm nearly certain that remoting isnt
what I'm looking for.
Essentially I'm wondering if anyone knows about threading issues when making
a windows service with Visual Studio, and also, if I need to create a
multithreaded application when using the FileSystemWatcher.
I've had a look around and haven't been able to find this information
(although I'm sure its there somewhere).
I'm just wondering if anyone knows the answer to these questions off the top
of their head
Thanks
Simon
Hi Simon,
I hope I understand your questions well.
Some answers.
If there is no need for a seperate thread, than do not use them, it is only
extra processing than.
But if it is a service that watches the systemfilesystemobject, you should
give on one or the other way the results to another program.
I thought for that is remoting the best way, as I pointed you on.
(you can do things with the main tread you are working with just with
something as)
threading.thread.sleep(4000); It is not case sensetive written have a look
for that yourself. Your program sleeps than 4 second.
Have a look at the walkthroughs on MSDN for multithreading and services http://msdn.microsoft.com/library/de...dsolutions.asp
I hope this helps?
Cor
Hi!
Clue points are:
- when you implement a system service, then you must stop all the processing in the OnStart method when the system service is starting; when the OnStart method finishes, then the service enters the "started" state; so, all your work in the OnStart must finish when the system service is starting and is only for initialization, not for main system service processing;
- in the OnStart method of the system service you may either start a new thread that watches the directory for you or setup the FileSystemWatcher to fire events and handle them in other methods (which is better in your case)
In the latter case you don't need to worry about thread. FileSystemWatcher will do all the work for you.
--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message news:ud**************@TK2MSFTNGP10.phx.gbl... Hi everyone, I need to make a service that monitors a directory for changes in the files contained within it. I have two questions: 1. I'm going to be using a FileSystemWatcher object to do the monitoring - but do I need to somehow involve another thread to allow the service to do other stuff as well, or is another thread created automatically when the FileSystemMonitor object is created? 2. Because I'm creating a service, and not an application, do I need to worry about threading at all? Is it possible that my service could try and steal all the processors resources, or does the operating system automatically give each service a shot of the processor such that I don't have to worry about it? Sorry, I'm a bit unkowledgeable in this area - I'm making an application for my boss though and I don't want to arse it up! :-) Thanks to nayone and everyone who can help Kindest Regards Simon
Thanks everyone,
Thats a great help!
I may have problems later but this info is definately enough to get me
going, so thank you very much!
Simon
Inline..
--
Manoj G [.NET MVP]
Site: http://www15.brinkster.com/manoj4dotnet
Blog: http://msmvps.com/manoj/
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl... Hi everyone,
I need to make a service that monitors a directory for changes in the
files contained within it. I have two questions:
1. I'm going to be using a FileSystemWatcher object to do the monitoring - but do I need to somehow involve another thread to allow the service to do other stuff as well, or is another thread created automatically when the FileSystemMonitor object is created?
[Manoj] Yes, the monitoring happens on a seperate thread from the thread
pool. This is done automatically. You dont need to worry. 2. Because I'm creating a service, and not an application, do I need to worry about threading at all?
[Manoj] Depends on what all purposes you use the service for. If your
service just does file system monitoring, then you dont really have to
bother much about threads, unless there is some objects shared between the
main thread and the thread executing the event handler. In this case, you
may need to synchronize these resources.
Is it possible that my service could try and steal all the processors resources, or does the operating system automatically give each service a shot of the processor such that I don't have to worry about it?
[Manoj] Oh yes, if you dont respect resources, you can screw the performance
of the system (spawing tens of threads with a high priority for instance).
And the OS schedules threads, not processes. A service is just another
process which has one or more threads.
For your simple file system monitor, this is not much of a problem Sorry, I'm a bit unkowledgeable in this area - I'm making an application
for my boss though and I don't want to arse it up! :-)
Thanks to nayone and everyone who can help
Kindest Regards
Simon
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fabio Papa |
last post by:
I am trying to write a windows service that sends emails to clients at
specific times based on information in a sql db. Since this is done for
multiple cities, I start a thread for each city and...
|
by: Simon Harvey |
last post by:
Hi everyone,
I need to make a service that monitors a directory for changes in the files
contained within it. I have two questions:
1. I'm going to be using a FileSystemWatcher object to do...
|
by: karl |
last post by:
I have a windows service that kicks off a 'monitor' thread which in
turn kicks off 4 additional threads. These 4 threads basically are
listen on a designated socket and report back any errors...
|
by: Jack David |
last post by:
I need direction on how to create a program that will start multiple windows
services. Each service will monitor a specific directory using
FileSystemWatcher. I have the file system watcher part...
|
by: Jeevan |
last post by:
Hi,
I am creating a Window Service in C-Sharp. The Window Service has a
reference to an OCX file created in VC++. In OnStart method I have created
an instance of the class, of the OCX file and...
|
by: Ekempd |
last post by:
Hi I need some advice about this situation an how I'm current handling it
I hava a ASP.NET solution that in some point start multiples lenghty
verification agains diferent databases, my big...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: Simon Harvey |
last post by:
Hi everyone,
We have a need to make a Windows Forms (2.0) client application that
will be installed on our clients site.
The data that the application uses needs to be centrally available to a...
|
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...
|
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,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |