473,503 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service Event Handling

Hi,
I am trying to use a 3rd Party telephony (Intel's CT-ADE 8.3) library in
a vb.net service.
The way it hangs up is to raise an Event.
If you build a windows Application you can write:
Sub DoSomeWork
While not Hungup
Do lots of good things
application.doevents
end While
end sub

The hangup event handler sets variable hungup to true.

In a service you do not have 'application.doevents'
So the eventhandler doesn't get a chance to set the variable.
Is these some equivalent to 'application.doevents' for services?
Thanks
Bob

Nov 20 '05 #1
3 3545
Hi Bob,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use the something
similar with Application.Doevents in windows service.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on my knowledge, Application.Doevents is used to Processes all
Windows messages currently in the message queue. The message is somewhat
different from the event we said in the RaiseEvent to some extent.

The event in the .net is similar with an callback mechanism, raiseevent is
somewhat similar with the call the delegate(i.e. the function point in C++
category)
You may take a look the link below about event and delegate.

Events and Delegates
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconeventsdelegates.asp

Raising an Event
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconprovidingeventfunctionality.asp

e.g.
[Service1]
Public WithEvents tc As TestClass

Protected Overrides Sub OnStop()
tc = New TestClass
Dim i As Integer
i = 0
While Not tc.flag
i += 1
If i > 4 Then
tc.FireEvent()
End If
End While
' Add code here to perform any tear-down necessary to stop your
service.
End Sub

Private Sub tc_TestEvent() Handles tc.TestEvent
tc.flag = True
End Sub

[TestClass]
Public Class TestClass
Public Sub New()
flag = False
End Sub
Public Event TestEvent()
Public Sub FireEvent()
RaiseEvent TestEvent()
End Sub
Public flag As Boolean
End Class

In the code snippet above, we do not need the mesage loop to fire the event
to set the flag.

If the control you are using is depended on the message loop to handle the
event, that is to say, if we must need to generate a message loop for the
windows service, which by default will not have the message loop, by
calling the System.Windows.Forms.Application.Run (please add reference to
the system.windows.forms.dll). But if we call it in the main thread, the
thread will be stop at the System.Windows.Forms.Application.Run() code
line. Usually we not use the message loop in the windows services, and it
is an backgroup application.

So I am not sure how do you change the value Hungup by raising event. Did
the snippet code I provide help you? Or can you provide more information
about how you change the Hungup? e.g. In which condition, you will change
the Hungup, do you have concern to run more than one thread in the windows
service, so that we can run the application.run in other thread, and handle
the message loop issue in that thead, if certain condition is met, we can
changed synchronized object's value to tell the main thread that something
had happened.

And what do you wants to use the third party library for?

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Hi Bob,

Did my suggestion help you?
If you still have any concern on this issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #3
Hi Peter,
My apologies for not replying sooner.
I have been out of the Office.
I have been having some seconds thoughts on the construction of the
service, so I won't bother you any more on this issue at present.
Thanks
Bob


Peter Huang wrote:
Hi Bob,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use the something
similar with Application.Doevents in windows service.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on my knowledge, Application.Doevents is used to Processes all
Windows messages currently in the message queue. The message is somewhat
different from the event we said in the RaiseEvent to some extent.

The event in the .net is similar with an callback mechanism, raiseevent is
somewhat similar with the call the delegate(i.e. the function point in C++
category)
You may take a look the link below about event and delegate.

Events and Delegates
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconeventsdelegates.asp

Raising an Event
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconprovidingeventfunctionality.asp

e.g.
[Service1]
Public WithEvents tc As TestClass

Protected Overrides Sub OnStop()
tc = New TestClass
Dim i As Integer
i = 0
While Not tc.flag
i += 1
If i > 4 Then
tc.FireEvent()
End If
End While
' Add code here to perform any tear-down necessary to stop your
service.
End Sub

Private Sub tc_TestEvent() Handles tc.TestEvent
tc.flag = True
End Sub

[TestClass]
Public Class TestClass
Public Sub New()
flag = False
End Sub
Public Event TestEvent()
Public Sub FireEvent()
RaiseEvent TestEvent()
End Sub
Public flag As Boolean
End Class

In the code snippet above, we do not need the mesage loop to fire the event
to set the flag.

If the control you are using is depended on the message loop to handle the
event, that is to say, if we must need to generate a message loop for the
windows service, which by default will not have the message loop, by
calling the System.Windows.Forms.Application.Run (please add reference to
the system.windows.forms.dll). But if we call it in the main thread, the
thread will be stop at the System.Windows.Forms.Application.Run() code
line. Usually we not use the message loop in the windows services, and it
is an backgroup application.

So I am not sure how do you change the value Hungup by raising event. Did
the snippet code I provide help you? Or can you provide more information
about how you change the Hungup? e.g. In which condition, you will change
the Hungup, do you have concern to run more than one thread in the windows
service, so that we can run the application.run in other thread, and handle
the message loop issue in that thead, if certain condition is met, we can
changed synchronized object's value to tell the main thread that something
had happened.

And what do you wants to use the third party library for?

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1613
by: Randy Geyer | last post by:
I have an NT/W2K service that spawns 3 worker threads that each do different things. For example, one monitors an email mailbox for incoming items and puts them in a queue for processing by a 2nd...
2
10448
by: Shads | last post by:
Hi, I receive this error in the System Event Log? Event Type: Error Event Source: Service Control Manager Event Category: None Event ID: 7031 Date: 15/08/2005 Time: 22:22:32
2
1330
by: Anony | last post by:
Hi All, After trying the Windows Service sample from MSDN, I don't get what the windows service class is better than a class handling and raising events itself. If using the...
1
1924
by: sidd | last post by:
Hi all, how do i exit out(unload) of a windows service in case of an error. so i have a code block as follows try { } catch(exception ex) { //log to event log
4
3291
by: Nathan Kovac | last post by:
I have a windows service project created with a timer that fires an event over and over. I created an installer & the service appears to install correctly. When I try to start the service I get a...
8
5784
by: SDS | last post by:
VS 2005 / .NET 2.0.50727 (Sept. CTP) I've got a Windows Service application that I've pushed out to a few other workstations. There is an unhandled except occurring somewhere in the application...
1
1524
by: Ron Bremmers | last post by:
Hello, I have a Windows Service which executes some code each 2 seconds. Every 2 seconds I want to log the result in a Windows Forms application. What is the best approach? I think it is...
0
1100
by: pdube | last post by:
I have been trying for a few weeks to have a service that calls a COM in .NET I made a service in .NET following simple instructions I found on the web. It worked fine. Then I needed to make a...
10
2446
by: Penelope Dramas | last post by:
Hello, I am using following code to handle unhandled exceptions in Windows Forms. Shared Sub Main() Dim GlobalExceptionHandler As New GlobalExceptionHandler AddHandler...
0
7205
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,...
0
7287
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
7349
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...
0
7467
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
5594
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,...
1
5022
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
4688
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
3177
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
1521
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.