473,466 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Blocking Method for a Service

7 New Member
Hi,

In my app, I am registering an event with WMI, and to make it wait for the event, I'm using Console.ReadLine() for blocking. But it seems that when I use the same code as Service, Console.ReadLine() doesn't work. The service is running as SYSTEM. The service terminates without waiting for WMI event. I'm using framework 2.0.

I have tried Thread.Sleep and EventWaitHandle. Those block the event too.
Please suggest a suitable replacement for Console.ReadLine().

Expand|Select|Wrap|Line Numbers
  1.  
  2.             ManagementOperationObserver managementOperationObserver = new ManagementOperationObserver();
  3.             ConnectionOptions opt = new ConnectionOptions();
  4.             opt.EnablePrivileges = true;
  5.             WqlEventQuery eventQuery = new WqlEventQuery();
  6.             eventQuery.EventClassName = "__InstanceModificationEvent";
  7.             eventQuery.WithinInterval = new TimeSpan(0, 0, 1);
  8.             eventQuery.Condition = @"TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5";
  9.             ManagementEventWatcher mewCDEvent = new ManagementEventWatcher(new ManagementScope("root\\CIMV2", opt), eventQuery);
  10.             try
  11.             {
  12.                 mewCDEvent.EventArrived += new EventArrivedEventHandler(mewCDEvent_EventArrived);
  13.                 mewCDEvent.Start();
  14.                 Console.ReadLine(); //doesn't work in Service
  15.                 Console.WriteLine("Done wid CD");
  16.             }
  17.             finally
  18.             {
  19.                 mewCDEvent.Stop();
  20.             }
  21.  
Aug 16 '07 #1
3 1240
Plater
7,872 Recognized Expert Expert
Well a service doesn't have a console, so reading a line from it shouldn't work to begin with.
Why make it a service if you want it to wait for a user input?

I am pretty sure that you can create an event/delegate for wmi events and stuff.
(I did one to determine when the network connectivity changed)
Aug 16 '07 #2
nrworld
7 New Member
U didn't understand my question. The service is not waiting. I want a suitable blocking call in place of Console.Readline.

Well a service doesn't have a console, so reading a line from it shouldn't work to begin with.
Why make it a service if you want it to wait for a user input?

I am pretty sure that you can create an event/delegate for wmi events and stuff.
(I did one to determine when the network connectivity changed)
Aug 17 '07 #3
Plater
7,872 Recognized Expert Expert
U didn't understand my question. The service is not waiting. I want a suitable blocking call in place of Console.Readline.
Blocking for how long?
Services aren't supposed to have any user interaction.
Thread.Sleep() is good for waiting for X amount of time.
Aug 17 '07 #4

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

Similar topics

3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
5
by: Simon Knox | last post by:
Hi I have a web app that has a legitimate use for pop up windows. My web app is an insurance quoting app. I use the window.open method to display another aspx page so that the user can check...
4
by: Jared | last post by:
I've got an app that requires communication with a remote web service. I've had customer reports of the "underlying connection was closed" error, and I assume this to indicate they've got Internet...
10
by: Brian Parker | last post by:
I inherited a C++ DLL that I need to remotely call multiple times asynchronously. What I have developed is: CSharp web application that makes asynchronous calls to a CSharp Web Service. The...
1
by: opi | last post by:
My blocking TCP server hangs in the Accept method when the client software sometimes gets an error. Are there any ways to stop this blocking in the Accept method so I dont have to restart the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.