Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

I've created this class with vb.net that watch a directory and every time it updates send me an email.

I've added that class to an application to do debugging and it worked great.

Then I've added the class to a Service and build it and installed it.

So far everything was great, the only problem is that now when I am updating the directory nothing happens. (off course I started the service and everything)

 

How can I debug the service?

Any idea why this happens?

THANKS!

Posted
Hi,

I've created this class with vb.net that watch a directory and every time it updates send me an email.

I've added that class to an application to do debugging and it worked great.

Then I've added the class to a Service and build it and installed it.

So far everything was great, the only problem is that now when I am updating the directory nothing happens. (off course I started the service and everything)

 

How can I debug the service?

Any idea why this happens?

THANKS!

 

 

Remoting services dont work like that. They are meant to sit idly on your computer until a request for an object is made. The object for monitoring your directory is running out of scope and being collected by the GC immediately after you start the service. You will need to create a windows executable (with an invisible 1x1 px form) and run that as the service if you wan't to continuously monitor a system directory.

Posted

here is the code

 

Does the account the service runs under have permissions to the directory in question? Also could you post the relevant code (service startup' date=' the monitor function etc)?[/quote']

 

this is in the service code:

Dim watcher As watcher = New watcher("c:\temp", "niros")

   Protected Overrides Sub OnStart(ByVal args() As String)
       ' Add code here to start your service. This method should set things
       ' in motion so your service can do its work.
       watcher.StartListening()

   End Sub

   Protected Overrides Sub OnStop()
       ' Add code here to perform any tear-down necessary to stop your service.
       watcher.StopListening()
   End Sub

then the Watcher.class code:

   Dim nPath As String, nEmail As String
   Dim watcher As New FileSystemWatcher
   Friend WithEvents timer As System.Windows.Forms.Timer

  Sub New(ByVal strPath As String, ByVal strEmail As String)
       nPath = strPath
       nEmail = strEmail
       watcher.Path = nPath

       timer = New System.Windows.Forms.Timer
       'timer = newTimer
       timer.Start()
       timer.Interval = 30000

       watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
       watcher.Filter = "*.*"

       AddHandler watcher.Created, AddressOf OnChanged
       AddHandler watcher.Changed, AddressOf OnChanged

   End Sub

   Public Sub StartListening()
       ' Begin watching.
       watcher.EnableRaisingEvents = True
   End Sub

   Public Sub StopListening()
       watcher.EnableRaisingEvents = False
   End Sub


   Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
msgbox("test")
   End Sub

 

as I said it work great when I am running it as a part of an application,

only when ill try to run it as service there are no reacts

thanks !

Posted

I was being serious when I said that you cannot run a remoting service like you are trying to. Remoting services were designed for RMI, not for running a dedicated process on the host machine. Throw some code into your app to write to the event log so you can see what is happening... the watcher object is being instantiated on start and is being eaten by the garbage collector soon thereafter.

 

To get the results you want you will need to forget about creating a remoting service and use a regular executable with an invisible form. Remoting services were not meant to be used like this and you are wasting your time if you don't believe me. There are plenty of other options available for you to get the results you want.

Posted

Why do you want a web service from a monitoring application that automaticly warn you when something change ???

 

a more detailed explication of how you would run your service would help us help you.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Hi, what is RMI?

I didn't saw your response before. what the program suppose to do is to send the files that are insert into the directory as email attachment and then delete them.

 

I though that its a perfect for a service that suppose to sit quietly in the background and work when needed, but I guess that I was wrong.

What are the options then to make this kind of thing? a �silent� application?? what is the best use for services?

 

Thanks

Posted

What I recommend you... is to install your application as a local service (not a Web Service).

 

Make it the most invisible as possible. (remove it from the taskbar... form invisible or console application that run in hidden mode... etc...).

 

That's my suggestion... other suggestions ?

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Hi, what is RMI?

I didn't saw your response before. what the program suppose to do is to send the files that are insert into the directory as email attachment and then delete them.

 

I though that its a perfect for a service that suppose to sit quietly in the background and work when needed, but I guess that I was wrong.

What are the options then to make this kind of thing? a �silent� application?? what is the best use for services?

 

Thanks

 

RMI is Remote Method Invocation, which is the reason Remoting Services were created in the first place (note the word Remoting ;) ). What you are trying to do has nothing to do with RMI, you just want to monitor a directory on your machine.

 

To run a regular service on your machine to do what you are looking to do you will need to create a regular Win32 app and configure Windows to start it automatically.

 

Honestly, I would do this by generating an app in JScript.Net and configure Windows Scripting Host to do the rest. You can use all of the same libraries with JScript.Net and take advantage of Windows Scripting Host as well. Good luck.

  • Administrators
Posted

Rodenberg - He doesn't mention anything about this involving remoting anywhere in his post - so I'm not sure why this would have any impact.

To create a regular windows service he needs to do what he is doing now - creating a service project. Services will run if a user is logged in or not, a normal application requires a user to be logged in. If this is a process that runs on a server having it logged in is generally a bad idea.

 

niros - not near a machine with .Net installed at the moment but off the top of my head you may need to look at threading, possibly launching the filesystem watcher in it's own thread during the service startup. However I should have access to .Net tomorrow and can have a look then.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Now I have some more questions:

 

Arch4ngel - I didn't try to make a web service, I tried to make a local one, how can I change mine to be a local one from what it is?

 

Rodenberg - what is "Windows Scripting Host" and why JScript.Net is the only one that can use it?

 

PlausiblyDamp - You are right; the idea is to put this thing on a server. the question is if ill make it as a separate thread, will it not be thrown to the GC as well?

 

Thanks you all for the help!

  • Administrators
Posted

The following 2 links may give you a bit more info - haven't had time to try them myself though....

http://www.c-sharpcorner.com/2/window_service.asp

 

http://www.fawcette.com/archives/premier/mgznarch/vbpj/2001/08aug01/ce0108/ce0108-1.asp <- is probably the better one to try.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...