472,805 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 5473
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.