473,786 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows service not working for everyone.

63 New Member
Hi I have already posted this question before.I got a work around but doesn't seem reasonable.

I developed a windows service and I installed it in our server.everybod y in the office has access to a folder in the server.anybody can put a file in that shared folder and the service has to pick it up. but it does not pickup for everyone. it just picks up for some users. and the strange thing is it pickes up for rest of the users also but ocassionally.

Iam not getting how to make it work consistantly. any ideas on this issue.

does it have to work under admin account. if so what should i do for that.

please help!
Ayush
Sep 15 '08 #1
30 3614
ayush patel
63 New Member
Hi
also another question right now I have my service running under network service account. what difference will it make if I run it under local system account. I am just accessing local drives on the server no remote or network drives are being accessed so is the local system account enough to do the job?

If anyone can tell me what is the difference between the two accounts it'll be a great help.
Ayush
Sep 15 '08 #2
PRR
750 Recognized Expert Contributor
"I developed a windows service and I installed it in our server.everybod y in the office has access to a folder in the server.anybody can put a file in that shared folder and the service has to pick it up. but it does not pickup for everyone. it just picks up for some users. and the strange thing is it pickes up for rest of the users also but ocassionally."
"
Iam not getting how to make it work consistantly. any ideas on this issue. "


Can you post a sample code... also are you using FileWatcher? What kinds of error, (in case you are getting) or exceptions are you gettin? Plz post more info and sample code...
Sep 15 '08 #3
ayush patel
63 New Member
Thanks for the quick reply.

yes I am using filewatcher. and the service works fine for me(Since I installed it on the server,I am asuming it'll work for me).

there is no error,service just termiates unexpectedly for some users who try to put a file in that folder. as a recovery action i made the service to restart. when the same user tries to put the file back in the folder it works. i dont know why it stops the first time.

Code:(text)

1. public Service1()
2. {
3. try
4. {
5. _timer = new Timer(6000);
6. InitializeCompo nent();
7. }
8. catch (Exception ex)
9. {
10. System.IO.Strea mWriter tw = new System.IO.Strea mWriter("C:\\gg gg\\jjjj\\error .txt", true);
11. tw.Write(ex);
12. tw.Close();
13. }
14. }




15. protected override void OnStart(string[] args)
16. {
17. try
18. {
19. _timer.Start();

20. FileWatch.Path = ConfigurationSe ttings.AppSetti ngs["WatchPath"];
21. FileWatch.Creat ed += new FileSystemEvent Handler(FileWat ch_Created);

22. }
23. catch(Exception ex)
{
24. System.IO.Strea mWriter tw = new System.IO.Strea mWriter("C:\\gg gg\\jjjj\\error .txt", true);
25. tw.Write(ex);
26. tw.Close();
27. }
28. }



29.private void FileWatch_Creat ed(object sender,
30. System.IO.FileS ystemEventArgs e)
31. {
32. string[] filedata = File.ReadAllLin es(e.FullPath);
33. int maxlins = filedata.Length ;

34. for (int i = 0; i < maxlins; i++)
35. {
36. TranslateForm form = new TranslateForm() ;
37. form.newpropert y(filedata, e);

38. }

39. }

hope this provides the information.do let me know if i have to answer any questions
Sep 15 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
Please start using [code] tags when you are posting your code.

You don't need to put the line numbers there, the forum software will do that for you.

MODERATOR
Sep 15 '08 #5
PRR
750 Recognized Expert Contributor
when you are transfering file from network or from computer to a destination folder which has a active watcher... the ownership of file is not available to watcher as soon as file is created... so try and pause for couple of seconds in "watcher_filecr eated" ... secondly when using windows service you need to use threading so as to "come back" to onstart as soon as possible...
Sep 15 '08 #6
ayush patel
63 New Member
Do you mean I should use "System.Threadi ng.Timer stateTimer" instead of "System.Tim ers"
Sep 15 '08 #7
balabaster
797 Recognized Expert Contributor
Are you finding that this is inconsistent? i.e. when only one user is using the service it works all the time, but when multiple users use the service, sometimes it fails for some users, but other times it doesn't fail for those users but fails for different users? Like, does it work sometimes for any given user and then fail on other times? It seems to me that this may be a classic deadlocking issue - when the server is trying to write to the file it locks the file and you can't read it during the timespan it takes for the server to write.

If this is what is happening, then you need to do something to alleviate this. I would write a queued read/write mechanism. i.e. you need the server to have an intermediate mechanism that can queue up reads and have clients talk to that mechanism instead of both trying to access the file directly. It works in the same fashion as the buffer on your hard disk. Files aren't accessed directly on the disk, you talk to the buffer, the buffer then gets what is on the disk and returns it to you. Likewise when the file is written, what you are writing goes into the buffer and the buffer writes to the file. This way you can alleviate this deadlocking issue that is caused by file locking.

As an example, the queuing mechanism might have some similar interface:
Expand|Select|Wrap|Line Numbers
  1. Public Class FileInterface
  2.  
  3. Private FileLockMechanism As New Object
  4. Private FilePath As String
  5.  
  6. Private Function WriteContent(ByVal stringToAdd As String) As Boolean
  7.  
  8.   SyncLock FileLockMechanism
  9.     'Do whatever you've gotta do to write to the file
  10.     'Create your writer in here...if you create it outside, it'll lock the file
  11.     'and then nobody will be able to read the file.
  12.   End SyncLock
  13.  
  14. End Function
  15.  
  16. Private Function ReadContent() As String
  17.  
  18.   SyncLock FileLockMechanism
  19.     'Do whatever you've gotta do to read from the file here.  You can create
  20.     'the reader at the class declaration level as the reader doesn't lock the
  21.     'file for writing.  If you're not constantly creating and destroying the reader
  22.     'then you're not wasting cpu cycles unnecessarily.
  23.   End SyncLock
  24.  
  25. End Function
  26.  
  27. Public Sub New(ByVal FileName As String)
  28.   FilePath = FileName
  29. End Sub
You'd then need to set up some kind of protocol for the client services to talk to this service. It's not particularly complex, you can use any number of mechanisms to do this. Remoting is probably the least complex to implement.
Sep 15 '08 #8
ayush patel
63 New Member
Thanks for the reply.
you are right about service being unpredictable there is also another problem with it. service terminates unexpectedly sometimes. when it restarts again it works fine. is this behavior also a deadlocking issue?
Sep 15 '08 #9
balabaster
797 Recognized Expert Contributor
Thanks for the reply.
you are right about service being unpredictable there is also another problem with it. service terminates unexpectedly sometimes. when it restarts again it works fine. is this behavior also a deadlocking issue?
I can't be 100% sure... the easiest method I can think to do this is by turning off the software that's writing to file for a moment... make sure all but one of the client services are shut off. Open the file in some simple application that doesn't lock the file - I assume it's a text file, so open it in notepad. Keep writing to the file and saving it and see if you can get the client service to hang or crash out. If it consistently works and doesn't fall over, then that kind of points towards locking causing the problem. Now, turn on all the client services and continue writing and saving with Notepad. They will probably all continue to function just fine. I would hazard a guess that it's the writing mechanism that's causing the issue as opposed to the client services. The client services are likely crashing because they're trying to read the file while it's locked by the server. Consequently if you push all the reads and writes through the same mechanism that streams data into the file and streams data out, then it will alleviate the problem. Alternatively, if you wrap the reads in something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim EndTime As DateTime = DateTime.Now().Add(New Timespan(0,0,10))
  2. While True And Now() < EndTime
  3.   Try
  4.     'Do stuff to read file
  5.     Exit While
  6.    Catch ex As Exception
  7.     'Ignore the error, we don't care
  8.    End Try
  9. End While
This kind of mechanism will continue to attempt to read the file until either it was read successfully or a preset timeout passes - in this case 10 seconds. Of course, the side effect of this is that there may be unnecessary network traffic may be generated during locking events. So as we say in England, it's swings and roundabouts - you make your trade-offs and choose your approach accordingly.

Simple code that's quick to implement catches the exception (which is inherently expensive) and causes potentially large amounts of requests for the file over the network. But it is simple and quick and gets you up and running right now. You just need to be aware of the side effects.

More complex code will prevent having to catch the exception, and will require only a single network call, the server will receive the request to read which will be put into a queue and will respond once the file is unlocked. But on the other hand, now you have to code the protocol for client-server communication, which makes future code maintenance potentially more difficult.
Sep 15 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2248
by: Andrei Prodan | last post by:
Hi everyone, I have a small piece of code which uses GetObject function and it is working fine in a windows application developed under .NET In a windows service application, the GetObject function returns an error: "Cannot create ActiveX component" Does anyone knows why ??
4
5926
by: Simon Niederberger | last post by:
Hi I need to create a MessageQueue in my C# service (running as SYSTEM). Users will have no permissions on this queue, so I can't look if messages are present. When setting MessageQueue.SetPermissions, I have the problem of knowing the Windows Group Name. I'd like to set Full Control to either Users or Everyone (doesn't really matter), but the service might run under English (Users, Everyone) or German Windows (Benutzer, Jeder). On a...
4
2236
by: Tim Golden | last post by:
Tim Golden enlightened us with: > > Well, I'm with you. I'm sure a lot of people will chime in to point > > out just how flexible and useful and productive Linux is as a > > workstation, but every time I try to use it -- and I make an honest > > effort -- I end up back in Windows > I'm curious, what do you mean with "it" in the part "every time I try > to use it"? Fair question. I have, over the years, installed and used Gentoo,
4
15895
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group : microsoft.public.dotnet.languages.csharp URL :...
7
3925
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 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?
0
1307
by: pithhelmet | last post by:
Hello everyone - I need to create a windows service that will watch for a specific dialog, and when found, send a keypress to the dialog. I have the service working, but when it tries to find the window (dialog) it always comes back with zero. Now - in my test application (not service) it runs fine....
0
2668
by: artsohc | last post by:
Hey Everyone, this is my first time posting so go easy on me. I am trying to hook up music-on-hold at the office I work at. I got all the music loaded and I got Windows Media Player working while the phones are on hold, but now I am trying to write a script that will allow Windows Media Player to run as a service so I can make it auto-start with out needing a user logged in on the computer. Also it would allow the music-on-hold to work if we...
1
2001
by: icecroft | last post by:
Hello everyone! We're running a windows service application and it gets this error: "the service did not respond to the start or control request in a timely fashion". It works in most machines but for these 2 other machines (from our consultant & client), one is running on WinXP and the other is Windows Server 2003, the application doesn't seem to run. In addition to this, the WinServer2003 machine logs this error in the System event...
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.