Hi all
I am building a small example VB application about event notify.
It is based on opennect notify example, that run fine, but in my application I obtain a "Cannot run \\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent", and I dont know why??.
Please, do you know what is wrong??
Thanks in advance.
This is my code:
Imports OpenNETCF.Win32.Notify
Imports OpenNETCF.Threading
Imports System.Threading
Public Class frmWakeUp2
Inherits System.Windows.Forms.Form
Friend WithEvents btnSalir As System.Windows.Forms.Button
Public Reminder As OpenNETCF.Threading.ThreadEx = Nothing
Public NotificationEvent As EventWaitHandle = Nothing
Public Saliendo As Boolean = False
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnActivarAlerta As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.btnSalir = New System.Windows.Forms.Button
Me.btnActivarAlerta = New System.Windows.Forms.Button
'
'btnSalir
'
Me.btnSalir.Location = New System.Drawing.Point(32, 248)
Me.btnSalir.Size = New System.Drawing.Size(168, 32)
Me.btnSalir.Text = "Salir"
'
'btnActivarAlerta
'
Me.btnActivarAlerta.Location = New System.Drawing.Point(33, 200)
Me.btnActivarAlerta.Size = New System.Drawing.Size(168, 32)
Me.btnActivarAlerta.Text = "Activar Alerta"
'
'frmWakeUp2
'
Me.ClientSize = New System.Drawing.Size(234, 295)
Me.Controls.Add(Me.btnActivarAlerta)
Me.Controls.Add(Me.btnSalir)
Me.Text = "Wake Up 2"
End Sub
Public Shared Sub Main()
Application.Run(New frmWakeUp2)
End Sub
#End Region
Public Sub HandlerNotifications()
Try
Dim runtime As DateTime = DateTime.Now
runtime = runtime.AddSeconds(70)
' Create event for notification.
NotificationEvent = New OpenNETCF.Threading.EventWaitHandle(False, OpenNETCF.Threading.EventResetMode.AutoReset, "OpenNETCFSampleNotifyEvent")
' Set up notification.
Notify.RunAppAtTime("\\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent", runtime)
While Not Saliendo
' Wait for the notification event to fire.
NotificationEvent.WaitOne()
' Let the notification subsystem know that it's
' done with the event.
Try
Notify.RunAppAtTime("\\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent", DateTime.MinValue)
Catch e As Exception
MessageBox.Show("Error notify.runappattime")
End Try
' Close event handle.
NotificationEvent.Close()
If Not Saliendo Then
' Notify the user that the event fired.
Me.Invoke(New EventHandler(AddressOf Notify_Fired))
' Create event for notification.
NotificationEvent = New OpenNETCF.Threading.EventWaitHandle(False, OpenNETCF.Threading.EventResetMode.AutoReset, "OpenNETCFSampleNotifyEvent")
' Set up notification.
runtime = DateTime.Now.AddSeconds(70)
Notify.RunAppAtTime("\\\\.\\Notifications\\NamedEvents\\OpenNETCFSampleNotifyEvent", runtime)
'Else
' MessageBox.Show("Saliendo!!!!")
End If
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)
' The notify event fired. Notify the user.
MessageBox.Show("The notification has fired.", "Notification")
End Sub
Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
Saliendo = True
If Not IsNothing(Reminder) Then
Dim notifyEvent As EventWaitHandle = New OpenNETCF.Threading.EventWaitHandle(False, OpenNETCF.Threading.EventResetMode.AutoReset, "OpenNETCFSampleNotifyEvent")
' Notify the thread to stop.
notifyEvent.Set()
notifyEvent.Close()
System.Threading.Thread.Sleep(2000)
Reminder = Nothing
End If
Application.Exit()
End Sub
Private Sub btnActivarAlerta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActivarAlerta.Click
Reminder = New OpenNETCF.Threading.ThreadEx(New ThreadStart(AddressOf HandlerNotifications))
Reminder.Start()
End Sub
End Class