1

I have windows service that is multi-threded, the threads contains while loop that should always be activated,socket thread which send errors from my other application that installed there, thread which initialize few timers when i start the thread its start for few sec, then throw exception which says that my service stopped working and ask to send the data to Microsoft. i don't know what make my service do it, probably the threads but i don't understand what wrong with my implementation in addition i use custom installer, when the user start the application it will install the service. tools is a class which contains static mathods. my code:

public partial class MyService : ServiceBase
{

    public static System.Timers.Timer key;
    public static System.Timers.Timer browse;
    public static System.Timers.Timer sender;

    // array of worker threads
    Thread[] workerThreads;

    public MyService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
        workerThreads = new Thread[] 
        { 
            new System.Threading.Thread(new ThreadStart(InitTimers)),
            new System.Threading.Thread(new ThreadStart(Tools.CheckApplication)), 
            new System.Threading.Thread(new ThreadStart(Tools.CheckBrowser)), 
            new System.Threading.Thread(new ThreadStart(Tools.SendOnError))
        };

        // start the threads
        for (int i = 0; i < workerThreads.Length; i++)
        {
            workerThreads[i].Start();
        }
    }

    protected override void OnStop()
    {
    }

    public void InitTimers()
    {
        key = new System.Timers.Timer();
        key.Interval = 1;
        key.Elapsed += Other.key_Tick;
        key.Enabled = true;

        browse = new System.Timers.Timer();
        browse.Interval = 1;
        browse.Elapsed += Other.browse_Tick;
        browse.Enabled = true;

        sender = new System.Timers.Timer();
        sender.Interval = 3600000;
        sender.Elapsed += Other.sender_Tick;
        sender.Enabled = true;

        key.Start();
        sender.Start();
        browse.Start();
    }
}

EDIT:

if i found the right log the exception is this:

The thread tried to read from or write to a virtual address for which it does not have the appropriate access.

never saw it... from what the exception coming from and why? p.s the log is the log that suppose to be sent to Microsoft, i didnt create event log so i don't think i have one

Xboxbo
  • 69
  • 6
  • Can you check the event log. The service should have created an error log which could contain additional information... You could also try the start the service using an admin user to check, if it's a permission issue. – Volkmar Rigo Aug 14 '14 at 09:21
  • One of your threads is failing... the code your posted looks fine... – rene Aug 14 '14 at 09:26
  • edited :added the exception – Xboxbo Aug 14 '14 at 09:40
  • comment out each of the new threads until you discover which one is throwing the error - then post the code for it if you still need help. – ajg Aug 14 '14 at 09:41
  • You may want to perform the checks mentioned at http://stackoverflow.com/a/3372358/292411 (same error message) – C.Evenhuis Aug 14 '14 at 09:42

1 Answers1

0

I guess from your code that you are accessing the browser on the desktop.

See How can I configure my windows service in the code to access the desktop?

Read both answers, one tells you how to enable access, the other one strongly suggests another design (client app that interacts with the service)

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115