Detect NetworkAvailabilityChanged in ApplicationEvents.vb - vb.net

VS2022, VB.NET, WinForms app. Following some web examples I tried (in ApplicationEvents.vb):
Imports System.Net.NetworkInformation
Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As Object, ByVal _
e As NetworkAvailabilityEventArgs) Handles Me.NetworkAvailabilityChanged
Debug.Print(e.IsAvailable.ToString)
End Sub
But I obtain this error:
Error BC31029: The 'MyApplication_NetworkAvailabilityChanged' method cannot handle the 'NetworkAvailabilityChanged' event because it doesn't have a compatible signature. (translated from italian lang)
Why??

Try this:
Imports System.Net.NetworkInformation
Private Sub MyApplication_NetworkAvailabilityChanged(sender As Object, e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
Debug.Print(e.IsNetworkAvailable.ToString())
End Sub

Related

Getting an access denied error when trying to pause/resume an outgoing message queue

Imports System.Messaging
Imports System.Collections
Imports MSMQ
Imports System.IO
Imports System
Imports System.Messaging.MessageQueue
Imports System.Runtime.InteropServices
Public Class PauseOutMessages
'Declare everything to be in the scope of all methods.
Dim mgmt As New MSMQManagement
Dim outqmgmt As MSMQOutgoingQueueManagement
Dim q As New MSMQApplication
Dim outgoingQueues As New ArrayList
Dim myQueue As New MessageQueue("FormatName:DIRECT=OS:myMachine\Private$\myQueue", QueueAccessMode.ReceiveAndAdmin)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each queue In q.ActiveQueues
If queue.IndexOf("DIRECT=") >= 0 Then
outgoingQueues.Add(queue)
End If
Next
End Sub
Private Sub Pause_Click(sender As Object, e As EventArgs) Handles Pause.Click
For Each queuePath In outgoingQueues
mgmt.Init(FormatName:=queuePath)
outqmgmt = mgmt.Pause()
Next
End Sub
Private Sub Restart_Click(sender As Object, e As EventArgs) Handles Restart.Click
For Each queuePath In outgoingQueues
mgmt.Init(FormatName:=queuePath)
outqmgmt = mgmt.Resume()
Next
End Sub
Private Sub Send_Click(sender As Object, e As EventArgs) Handles Send.Click
myQueue.Send("Test")
For Each queue In q.ActiveQueues
If queue.IndexOf("DIRECT=") >= 0 Then
outgoingQueues.Add(queue)
End If
Next
End Sub
End Class
Here is the code I am using, by sending the test message to a non-existing path it gets stuck in the outgoing queue where I want to be able to call MSMQOutgoingQueueManagement.Pause or .Resume to be able to start and stop all outgoing queues.
However I keep getting an error on either mgmt.Pause() or mgmt.Resume() saying Access is denied. I can't seem to find a way to get on to the properties of outgoing queues to be able to adjust security settings. Any help would be greatly appreciated!
SOLVED!
Turns out I just needed to start up visual studio as an administrator and then it worked.

Emgu webcam in VB beginner

lets go with the idea that i know nothing about nothing...
https://www.youtube.com/watch?v=37l6-O0T6EA
I was following this vids, all going well. but failing on "capturez.QueryFrame"
Imports Emgu.CV
Imports Emgu.CV.Util
Imports Emgu.CV.Structure
Public Class Form1
Dim capturez As Capture = New Capture
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim imagez As Image(Of Bgr, Byte) = capturez.Retrieve() 'Instead of QueryFrame, you may need to do RetrieveBgrFrame depending on the version of EmguCV you download.
PictureBox1.Image = imagez.ToBitmap()
End Sub
End Class
There is no Retrieve() method in vb.
Try to replace capturez.Retrieve() with capturez.QueryFrame() or Capturez.RetrieveBgrFrame().
If you already changed that but you get failing on capturez.QueryFrame, it means you are missing some dll files in x86 (bin/debug).

using GoogleEarth plugin from VB.NET through FC.GEPluginCtrls

I'm really looking for a simple way to build VB.NET apps that use the GEplugin. So I have found this project that seems to do the dirty job I need: http://code.google.com/p/winforms-geplugin-control-library/
Well, all the code posted there around works on C#, but I need to have it on VB.NET. So I have tried this:
created a new 32-bit solution from VB.NET 2010 Express (I simply added
<PlatformTarget>x86</PlatformTarget >
inside the .vbproj file)
added a reference to FC.GEPluginCtrls.dll
inserted a GeWebBrowser control on the form
at the top of the code, added
Imports FC.GEPluginCtrls
then, in the form Load event, put this code:
InitializeComponent()
GeWebBrowser1.LoadEmbeddedPlugin()
Do
Loop Until GeWebBrowser1.PluginIsReady = False
GeWebBrowser1.CreateInstance(ImageryBase.Earth)
that, I think, would be equivalent to
http://code.google.com/p/winforms-geplugin-control-library/wiki/CreateInstance
So, the project compiles and doesn't get errors, but the GeWebBrowser control remains empty.
I actually wrote the library you are using. You are not listening for the PluginReady event. http://code.google.com/p/winforms-geplugin-control-library/wiki/PluginReady
To use it with VB simply convert the basic examples to VB -
http://code.google.com/p/winforms-geplugin-control-library/wiki/ExampleForm
Also, a loop polling PluginIsReady is totally unnecessary as the PluginReady event is asynchronous.
To show the earth all you would need is the following.
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GeWebBrowser1.LoadEmbeddedPlugin()
End Sub
To use the plugin when it has initialzesd use the PluginReady event. Something like.
Option Strict Off
Public Class Form1
Private Dim _ge as Object = Nothing
Private Sub GeWebBrowser1_PluginReady( ByVal sender As System.Object, ByVal e As FC.GEPluginCtrls.GEEventArgs) Handles GeWebBrowser1.PluginReady
_ge = e.ApiObject ' reference to the Google Earth Plugin object
MessageBox.Show(_ge.getApiVersion()) ' _ge is the plugin -use it just as in the javascript api...
End Sub
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GeWebBrowser1.LoadEmbeddedPlugin() ' load the plugin
End Sub
End Class

System.Threading.Timer not firing, global.aspx

I am a newbie, but I am unable to get this code working. FileSweeper is supposed to start a timmer that triggers fileCopy on a web server. fileSweeoer is triggered by global.asax. FileCopy then will copy the file. However the FC.copy never fires. Any help/explanation would be helpful!
Would it make any difference if this was a class running on a web server?
My code is from http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx.
Imports Microsoft.VisualBasic
Imports System
Imports System.Threading
Public Class fileSweeper
Dim stateTimer As Timer
<MTAThread()> _
Sub Main()
Dim FC As New fileCopy
Dim tcb As TimerCallback = AddressOf FC.Copy
stateTimer = New Timer(tcb, "", 20000, 200000)
GC.KeepAlive(stateTimer)
End Sub
End Class
Global.asax:
<%# Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Dim FS As New fileSweeper
FS.Main()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
</script>
You are probably going to get unexpected results here because you are likely going to get multiple sessions on a web server. You might want to consider creating a console app and using windows task scheduler.

Lua in Visual Basic.net

I'm trying to just get a VB.net app to be able to execute a lua script in a external file, and be able to add some functions to lua too, To do this I have this code:
Imports LuaInterface
Public Class Form1
Public luascripting As New Lua()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
luascripting.RegisterFunction("DisplayText", Me, Me.GetType().GetMethod("DisplayText"))
luascripting.DoFile("script.lua")
End Sub
End Class
But it errors on the register function, saying "Object reference not set to an instance of an object." Do you know of a example VB.net project that uses lua? Or know how to fix this?
You are registering a function but you forgot to write it. Paste this into your form code:
Public Sub DisplayText()
MsgBox("Works")
End Sub