Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a windows service in C# with WiX application to send data to the server automatically. So, I have used thread for capturing and sending the data to the server. Below is my code.
C#
protected override void OnStart(string[] args)
{
    trd = new Thread(new ThreadStart(ThreadTask));
    trd.IsBackground = true;
    trd.Name = "My Worker Thread";
    trd.Start();
}

public void ThreadTask()
{
    while (true)
    {
        SendData();
        Thread.Sleep(3000);
    }
}

public void SendData()
{
    // Here is the code to send data to the server through HttpWebRequest.
}


I am using HttpWebRequest for data sending. This application is able to send the data to the server in Debug mode, but as soon as I run this application normally after building the setup .msi file through WiX, the Windows Service gets started normally but the application does not send the data. Whereas I have also tested that the thread is running fine through service when I put a simple file write in the thread inside a function under OnStart method.

Is it a matter of week internet or something else is happening. At one hand the Service is running well, on the other hand data is successfully sent in Debug mode, only that without Debug, data is not sent through Service. Please help me get through this as soon as possible.

Any kind of help will be highly appreciated.

Thanks in advance.
Posted
Updated 23-Aug-14 4:36am
v2
Comments
[no name] 23-Aug-14 10:43am    
What are you doing for logging? Check the log files for the exceptions being thrown. Check the event logs. Check that the user account has permissions.
Tutun2014 27-Aug-14 5:39am    
I have work around the process and found that the application is able to send the active browser title and url both from Firefox and Chrome to the Server in Debug as well as in Release mode; but when I have used to run this Application using Windows service, firefox shows: **The client failed to connect to "firefox|WWW_GetWindowInfo". Make sure the server application is running and that it supports the specified service name and topic name pair**. In case of chrome, **MainWindowHandle becomes zero in everytime**. I have used **DdeClient** for firefox and **AutomationElement** for chrome.
Yvan Rodrigues 23-Aug-14 15:58pm    
Why are you creating another thread?

1 solution

Did you use fiddler
http://www.telerik.com/download/fiddler[^]
See whats happening at an HTTP level, request/response etc. Probably an access rights issue(just a thought).
 
Share this answer
 
Comments
Tutun2014 27-Aug-14 5:39am    
I have work around the process and found that the application is able to send the active browser title and url both from Firefox and Chrome to the Server in Debug as well as in Release mode; but when I have used to run this Application using Windows service, firefox shows: **The client failed to connect to "firefox|WWW_GetWindowInfo". Make sure the server application is running and that it supports the specified service name and topic name pair**. In case of chrome, **MainWindowHandle becomes zero in everytime**. I have used **DdeClient** for firefox and **AutomationElement** for chrome.
Rajiv Gogoi 27-Aug-14 12:51pm    
You are sending data using HTTP from a windows service to a web server,right. Then how did Firefox and Chrome come into the picture. M not able to understand.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900