WakeUp-Event and Programm hangs

V

verenadoll

Hello NG,

i use the following code to check if the device wakes up. It works
fine, but when i close the programm the process will not be
terminated. in the task manager the programm is listed as "background
process".

Whats wrong with the code.

Thanks and regards, Verena


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++

Imports System.Runtime.InteropServices
Imports System.Threading
Imports OpenNETCF.WindowsCE.Notification
Imports OpenNETCF.Threading

Public Class Form1
'Declarations:
Public SyncEndEventThread As OpenNETCF.Threading.Thread2 = Nothing
Public NotificationEvent As OpenNETCF.Threading.EventWaitHandle =
Nothing

Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Create thread that monitors the Active Sync Event
SyncEndEventThread = New OpenNETCF.Threading.Thread2(New
ThreadStart(AddressOf HandlerNotifications))
End Sub

Public Sub HandlerNotifications()

Try
' Create event for notification.
NotificationEvent = New OpenNETCF.Threading.EventWaitHandle
(False, OpenNETCF.Threading.EventResetMode.AutoReset, "WakeupEvent")

' Set up notification.
Notify.RunAppAtEvent("\\.\Notifications\NamedEvents
\WakeupEvent",
OpenNETCF.WindowsCE.Notification.NotificationEvent.Wakeup)

While True
' Wait for the notification event to fire.
NotificationEvent.WaitOne()

' Let the notification subsystem know that we're done
with the event.
Notify.RunAppAtEvent("\\.\Notifications\NamedEvents
\WakeupEvent",
OpenNETCF.WindowsCE.Notification.NotificationEvent.None)

' Close event handle.
NotificationEvent.Close()

' Notify the user that the event fired.
Me.Invoke(New EventHandler(AddressOf Notify_Fired))

' Recreate the event for notification.
NotificationEvent = New
OpenNETCF.Threading.EventWaitHandle(False,
OpenNETCF.Threading.EventResetMode.AutoReset, "SyncEndEvent")

' Set up notification.
Notify.RunAppAtEvent("\\.\Notifications\NamedEvents
\WakeupEvent",
OpenNETCF.WindowsCE.Notification.NotificationEvent.Wakeup)
End While

Catch ex As Exception
MessageBox.Show("HandlerNotifications: " & ex.Message)
End Try

End Sub

Public Sub Notify_Fired(ByVal sender As System.Object, ByVal e As
System.EventArgs)
MessageBox.Show("The notification has fired.", "Notification")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
SyncEndEventThread.Start()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
SyncEndEventThread.Suspend()
End Sub
End Class
 
C

Chris Tacke, eMVP

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread. WaitOne is a blocking
system call, and your thread will live until it gets released. As a general
rule, you should *never* call WaitOne without a timeout value. Adding a
timeout would allow the thread to unblock and the scheduler to let it die.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
C

Chris Tacke, eMVP

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread. WaitOne is a blocking
system call, and your thread will live until it gets released. As a general
rule, you should *never* call WaitOne without a timeout value. Adding a
timeout would allow the thread to unblock and the scheduler to let it die.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
V

verenadoll

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread.  

Hello Chris,

thanks for answering. The Problem is solved.
Bit i´m interested what things you do differently in this case. Maybe
you can tell me, what i have to modify or show me a sample

Regards, Verena
 
V

verenadoll

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread.  

Hello Chris,

thanks for answering. The Problem is solved.
Bit i´m interested what things you do differently in this case. Maybe
you can tell me, what i have to modify or show me a sample

Regards, Verena
 
V

verenadoll

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread.


Hello Chris,

thanks for answering.
I´m very interested what things you do differently in this case.
Maybe
you can tell me, what i have to modify or show me a sample


Regards, Verena
 
V

verenadoll

There are a load of things there I'd do differently, but the one causing the
problem is the call to WaitOne in a worker thread.


Hello Chris,

thanks for answering.
I´m very interested what things you do differently in this case.
Maybe
you can tell me, what i have to modify or show me a sample


Regards, Verena
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top