Closing main form doesn't finish process (only some computers) - vb.net

The problem is happening on 2 of the company's computers and on a client computer, but we can not identify a pattern.
I was able to reproduce the error using a simple program that only opens an OpenFileDialog. The program must be run by the generated executable itself (NOT by Debug) and it is still running in the background even after closing. Below is the code of the program, along with a link to download the project and a video demonstrating the error.
Code:
Public Class Form1
Private ofdAbrir As Windows.Forms.OpenFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ofdAbrir = New Windows.Forms.OpenFileDialog
ofdAbrir.ShowDialog()
ofdAbrir.Dispose()
ofdAbrir = Nothing
End Sub
End Class
As you can see in the code above, I only have one form, so it is not the case that some form remains open and it is also not related to threads running since none is created.
To reproduce the problem, click on Button1, cancel the OpenFileDialog and try to close the form (clicking on X). The form apparently will close, but you will see at task manager that it still running. The big mystery is that this problem does not happens in all computers.
Video: https://drive.google.com/open?id=1sfdVUGQlwYNCQkl1Ht-cJSOb4433sqnT
Project: https://drive.google.com/open?id=1d4oJYUjaaZ9xnRj4CX3HXOQPqwMZmE0V

I couldn't reproduce the problem, but how about using this method:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using ofdAbrir As New Windows.Forms.OpenFileDialog
ofdAbrir.ShowDialog()
MsgBox(ofdAbrir.FileName)
End Using
End Sub

I've seen the video u posted...It is not your application that is running rather it is the vsHost.exe that is running :)...The problem shouldn't occur if u run the app outside visual studio.
If the problem is still there,just disable Enable Diagnostic Tools while debugging from Tools > Options > Debugging > Uncheck Enable Diagnostic Tools while debugging
Also u can disable Visual Studio hosting service from Project > Project Properties > Uncheck Enable the Visual Studio hosting service

Related

VB Forms don't recognize each other in the same project

Hi everyone I need some help,
I am having a weird situation every time I try to call a window form I get this error
BC30469 Reference to a non-shared member requires an object reference.
I was originally working on Visual Studio 2010 when the first time contouring this problem so I thought that I may accidentally deleted or edited some code in the declaration of the form witch caused the problem so I closed the solution and created a new one to make sure that the problem is limited the solution not to VS. then I add window form "Form2" then created/added a button1 on Form1 to call Form2.Show()
simple code that should work fine but when I tape Form2.Show() it give that ERROR and red mark Form2
so I uninstalled VS2010 then Reset Windows 10 with option to wipe out all data on windows partition (I now that was extreme but I suspected that maybe the system was infected with some virus "prior action") so after that I checked the system with HitmanPro and found nothing then I installed VS2019 Community and get The some problem I searched on the web but did not found any similar case so here I am hoping that someone will resolve the mystery.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
Form2 is empty form I didn't make any change on it
Before this problem showing up everything work fine now even old project have the same issue
Thanks
Edit: Add project as simple
https://mega.nz/file/FgoXkCwA#ootxYrXGnR6sQR_Pifjvz617-r_Az1ozXWB49oGxqKU
the project dose not contain any executable file
I usually do something like this when calling a subform:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' using a Using block:
Using form2 as New Form2
form2.ShowDialog(Me)
form2.Close()
End Using
' using a With block
With New Form2
.ShowDialog(Me)
.Close()
End With
End Sub
ShowDialog(Me) keeps the subform open until a DialogResult is provided by the user (OK or Cancel usually).

Get focus back when clicked outside the form

I wrote a program to controle the audio volume by a remote control.
It needs to keep focused, otherwise it does not receive its commands anymore.
In order to get the focus back a used a timer, checking every second if the form still has the focus.
Here is the code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Not Me.Focused Then
Me.Activate()
End If
End Sub
As long as I run it from within Visual Studio this works perfect.
When I close Visual Studio it does not take the focus back anymore.
I ran the program on another computer on which was no Visual Studio installed and it works!
What could be the problem?

Disconnecting iTunes COM

I'm currently working with the iTunes COM with .NET, and something I came across previously, which stopped me using it, has happened again and I can't for the life of me figure it out.
When I go to close iTunes during or after my program has closed, it tells me something is still using the "Application Scripting Interface", COM is still connected.
This is what I have (removed what is not required)
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandler itunes.OnAboutToPromptUserToQuitEvent, AddressOf itunes_OnAboutToPromptUserToQuitEvent
End Sub
Private Sub itunes_OnAboutToPromptUserToQuitEvent()
System.Runtime.InteropServices.Marshal.ReleaseComObject(itunes)
End Sub
So, the above code does disconnect the COM to the extent that I need to restart iTunes to use it again, but, it doesn't get rid of the Application Scripting error. Meaning, I still need to click quit after the error dialog comes up. Everything else works fine, apart from this.
Any idea?
-- I've had a look at other questions that had this issue, but none of them resolved it for me. I'm not sure if the event doesn't work anymore with this current version of iTunes, but, it doesn't seem to work currently either way.
Had same issue with COM and Office, this solved it;
While System.Runtime.InteropServices.Marshal.ReleaseComObject(itunes) <> 0
Application.DoEvents()
End While

Open TCP/IPv4 dialog with visual basic button

I have a button in visual basic. I would like, when I hit the button for it to open up the TCP/IPv4 dialog window of the active network connection on the machine so that I can quickly and easily change ip address settings.
I can't seem to find a way to google this properly. All ways I can think to ask the question return unrelated results.
How do I open this dialog window with VB code?
Private Sub Button27_Click(sender As Object, e As EventArgs) Handles Button27.Click
End Sub
I'm not too sure if you can get it to open up straight at the WiFi properties of the current connection, but you can get it to open the Network Connections which should be able to save you some time.
Private Sub Button27_Click(sender As Object, e As EventArgs) Handles Button27.Click
Process.Start("ncpa.cpl")
End Sub
You cant open it directly but this article has a method using #Werdna's approach of using ncpa.cpl and send keys.
It also has the command line utilities for extracting / setting the ip.
https://superuser.com/questions/735292/how-to-open-tcp-ip-properties-from-cmd-or-run-directly

visual basic .net continue application

I just stat to study visual basic .net
I would like to ask about how to continue application.
For example
Private Sub UI_BT_SAVE_STOP_Click(sender As Object, e As EventArgs) Handles UI_BT_STOP.Click
Stop
End Sub
then , application will stop on the middle of processing(like a stop button on the visual studio)
I was trying to make continue button, but I can not find continue function to change my application status from stop to continue.
is there anyway to continue application again ?
thanks
There's nothing quite like that but you could always try importing the sleep function, seen here:
https://stackoverflow.com/a/469358/1504882
This will suspend everything the application is doing though.