windows-services

Receiving MSMQ messages with Windows Service

大城市里の小女人 提交于 2019-11-27 14:14:19
问题 I'm creating a Windows Service in C#. What is the best way to listen for messages?? How do I code this properly?? 回答1: You don't listen. You configure MSMQ Activation to activate your component when messages arrive. The link has all the details you need, code and configuration. 回答2: As previously stated, MSMQ Activation is probably the best way, if you can use that. Alternatively, here is code that I've used: var ts = new TimeSpan(0, 0, 10); MessageQueue q = GetQueue<T>(); while (true) { try

C#: GUI to display realtime messages from Windows Service

戏子无情 提交于 2019-11-27 14:12:45
I've written a C# windows service which can write messages to a custom EventLog or to any number of files. These messages are all marked with some priority (so, for example, only ERRORs and WARNINGs get stored in the EventLog, but if desired a lot more can be stored to a file). What I'd like to do now is create a GUI that can listen for these messages and display them in real-time. Allowing a user to watch the current messages (at whatever their desired priority level), without the need to store everything to a file. I assume this is a separate program with some form of hook into the service,

Bulk Insert Sql Server millions of record

♀尐吖头ヾ 提交于 2019-11-27 14:07:18
I have a Windows Service application that receives a stream of data with the following format IDX|20120512|075659|00000002|3|AALI |Astra Agro Lestari Tbk. |0|ORDI_PREOPEN|12 |00000001550.00|00000001291.67|00001574745000|00001574745000|00500|XDS1BXO1| |00001574745000|›§ IDX|20120512|075659|00000022|3|ALMI |Alumindo Light Metal Industry Tbk. |0|ORDI |33 |00000001300.00|00000001300.00|00000308000000|00000308000000|00500|--U3---2| |00000308000000|õÄ This data comes in millions of rows and in sequence 00000002....00198562 and I have to parse and insert them according to the sequence into a database

Windows Service hosted WCF over HTTPS

Deadly 提交于 2019-11-27 13:43:50
问题 I've created and configured an SSL certificate as per these instructions from MSDN. I'm getting the error message that this question lists, but am not sure how to map the accepted answer in that question to my App.config file. The content of the config file, and the service itself worked correctly over http, it's just over https that the problem is occuring. My App.config file is currently: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding

System error 5 Access is denied when starting a .NET service

一世执手 提交于 2019-11-27 13:24:51
When I try to start a service I created in Visual Studio I receive the following error: System error 5 has occurred. Access is denied. I am running the command line with elevated privileges, so it's not that problem. Is there any place I can look to see what error is occuring. To get it to work I needed to add permissions to the output bin\debug folder for my service project. The Local Service account didn't have permissions to the output .exe file, and this was why the error was occuring. Had the same issue. Fixed by running the service under "Local System Account" hfrmobile In my case the

Hosting WCF service inside a Windows Forms application

浪尽此生 提交于 2019-11-27 13:21:22
I need to host a WCF service inside a Windows Forms application and call the WCF service from a Windows service that will send data to the WCF service which will show it in the Windows Forms application (desktop application). How can I implement this? I need code that is working correctly and tried before. Keeper This code should be enough to get you started: Form1.cs namespace TestWinform { public partial class Form1 : Form { private ServiceHost Host; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Host = new ServiceHost(typeof(MyWcfService));

How to let Timer skip tick if the previous thread is still busy

a 夏天 提交于 2019-11-27 13:17:54
I created a windows service, that is supposed to check a certain table in the db for new rows every 60 seconds. For every new row that was added, I need to do some heavy processing on the server that could sometimes take more than 60 seconds. I created a Timer object in my service, that ticks every 60 seconds and invokes the wanted method. Since I don't want this timer to tick while processing the new lines found, I wrapped the method in a lock { } block, so this won't be accessible by another thread. It looks something like this : Timer serviceTimer = new Timer(); serviceTimer.Interval = 60;

Alternative to “Allow service to interact with desktop”?

落花浮王杯 提交于 2019-11-27 13:13:30
I have a windows service (C#) installed on a server that launches every 10 minutes an executable file (C#) to process some images from one directory to another. No interaction is required with any user. Nevertheless, since the executable file as an output window, to make the service run I have to enable the " Allow service to interact with desktop " checkbox which is considered as an insecure and bad practice . How would I go about this problem? I like to have the executable separated from my windows service because it makes it easier to debug and doesn't require a full windows service

How can I set up .NET UnhandledException handling in a Windows service?

岁酱吖の 提交于 2019-11-27 13:01:31
protected override void OnStart(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Thread.Sleep(10000); throw new Exception(); } void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { } I attached a debugger to the above code in my windows service, setting a breakpoint in CurrentDomain_UnhandledException, but it was never hit. The exception pops up saying that it is unhandled, and then the service stops. I even tried putting some code in the event handler, in case it was getting

Accessing Environment Variables from Windows Services

允我心安 提交于 2019-11-27 12:55:36
问题 I am attempting to write a Windows Service in C#. I need to find the path to a certain file, which is stored in an environment variable. In a regular C# console application, I can achieve that with the following line: string t = System.Environment.GetEnvironmentVariable("TIP_HOME"); If I write that to the console I see that it was successful. Now, if I try that same code in a Windows Service, the string t is empty. Any idea why? 回答1: I've no idea if this is useful, but I've found that for