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

Problems with Filesystemwatcher and Web Service

I am trying to find out if there is a way to tell if there is already a
filesystemwatcher (created by a webservice) monitoring a folder.

I have a webservice that creates a filesystemwatcher, monitors a folder and
then returns the contents of the new/changed files. However, if the client
app loses connection to the webservice without closing the filewatcher, and
then reconnects (and thus creates a new watcher), I believe I end up with two
watchers which is causing a few problems.

Is there anyway to tell if a filesystemwatcher already exists and is
watching the folder? Or that the webservice that created the first watcher is
still running?


Sep 20 '07 #1
5 5539
Hi,

Web Service is a stateless remote call, it does not have the session
feature by default unless you set EnableSession property of the
WebMethodAttribute. Even you enabled the session, you still have to
explicitly add the object references into the Session collection to use it.
Do you enable session in your Web Service? If so, do you add
FileSystemWatcher object into the Session collection?

Regarding your question, I do think it should not be a problem. Whether
your client is disconnected or killed abnormally, the server-side Web
Method will exit(this is the key point) and the Web Service processing
thread will return to the ThreadPool. So, all the stack references in the
Web Method will be released automatically by the stack unwind. Since the
references to the FileSystemWatcher disappeared, the FileSystemWatcher
object will be collected by the GC in future or immediately based on the GC
algorithm. So, once the WebMethod exited, the FileSystemWatcher objects are
guaranteed to be collected by GC, no leak will occur.

If you wanted to ensure the FileSystemWatcher object is collected
immediately, I would recommend you to wrap the object using C# "using"
keyword or place the FileSystemWatcher.Dispose() method calling in a
try...finally clause. This will ensure the FileSystemWatcher.Dispose() when
the WebMethod exits. FileSystemWatcher.Dispose() internally stops the
directory monitoring.

If you are not familiar with C# "using" keyword, please refer to the MSDN
link below, this is called C# deterministic cleanup:
http://msdn2.microsoft.com/en-us/lib...02(VS.80).aspx

Finally, I am curious about how do you use FileSystemWatcher in a
WebMethod? Based on my knowledge, FileSystemWatcher will monitor a
directory consistently, but WebMethod is one-off stateless calling from
client, FileSystemWatcher will be collected after the call. Do you spawn a
second worker thread to use FileSystemWatcher?

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 21 '07 #2
Hi,

Have you reviewed my reply to you? Does it make sense to you? If you still
need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 25 '07 #3
Hi,

Thanks for your reply. It made sense and helped me make several steps forward.

Thanks again
Sep 25 '07 #4
Glad to see it helps. If you need further help or have any other concern,
please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 25 '07 #5
Hi

I'm working on a VB web service at the moment and want to use the
Filesystemwatcher to monitor a directory but like Jeffrey said how do you get
it to work with the web service which is stateless???

Thanks in advance, Matt

"John S" wrote:
I am trying to find out if there is a way to tell if there is already a
filesystemwatcher (created by a webservice) monitoring a folder.

I have a webservice that creates a filesystemwatcher, monitors a folder and
then returns the contents of the new/changed files. However, if the client
app loses connection to the webservice without closing the filewatcher, and
then reconnects (and thus creates a new watcher), I believe I end up with two
watchers which is causing a few problems.

Is there anyway to tell if a filesystemwatcher already exists and is
watching the folder? Or that the webservice that created the first watcher is
still running?

Oct 4 '07 #6

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

Similar topics

1
by: Rich Miller | last post by:
Previously posted on the VB newsgroup with no replies, so any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that...
1
by: A Hirsi | last post by:
Hi I am planning to use the filesystemwatcher to monitor an ftp site for changes to a file. I would like to download the file if it changes and process it locally. I read somewhere that I do not...
1
by: Andreas | last post by:
Hi, we have some problems with the following situation: A remote application A writes files to a directory monitored by a FileSystemWatcher-instance in application B. A creates the file with...
2
by: Jet Leung | last post by:
Hi all, I had made a program to watching files in my directory. I had used a instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , for example onChange,...
2
by: Bonnett | last post by:
I have made a simple console application that creates a webpage from my playlist, then uploads it to my webhost. I decided to convert it to a windows service and use the FileSystemWatcher to...
2
by: Sacha Korell | last post by:
I need to set up a FileSystemWatcher in my web application (to automatically process uploaded files) and I'm trying to decide where to set it up. I would like to keep it within the web app, but it...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
0
by: Rich Miller | last post by:
Any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is...
1
by: D2 | last post by:
Hi, We are using FileSystemWatcher class in a windows service to monitor a directory "d:\abc". This path is configured in a config file. When the service is running and FSW is watching this...
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: 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?
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.