473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

When closing an executed application, my program is in background

Hi there!

I've got a problem with no solution, I hope you might help me.

I am writing a small tool with many buttons. Every button starts a
thread and this thread starts something else, in the example posted
below, the hardware configuration dialog. My problem is, that
sometimes when I close the executed program / application / dialog, my
program is displayed in background. When I execute the taskmanager,
everything works fine, but when I execute e.g. the hardware
configuration dialog, this behaviour occurs. Can somebody tell me why
and how to avoid this? (I don't want a topMost-application).

Using the shell()-command leads to the same behaviour.

Thanks in advance, best regards,
Sebastian

The button-click-action is:

Private Sub butSettingsHardware_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
butSettingsHardware.Click
Dim functionName As String = "butSettingsHardware_Click"
Try
Dim myThread As New Thread(AddressOf
threadOpenSettingsHardware)
myThread.Start()
Catch ex As Exception
exceptionLogging(ex, className, functionName)
End Try
End Sub

The started thread is:
''' <summary>
''' Öffnet die Hardware-Einstellungen
''' </summary>
''' <remarks></remarks>
Private Sub threadOpenSettingsHardware()
Dim functionName As String = "threadOpenSettingsHardware"
Try
Dim programName As String = "Display-Einstellungen"
Dim program As String = "rundll32.exe"
Dim arguments As String = "shell32.dll,Control_RunDLL
sysdm.cpl,,2"

executeProgram(programName, program, arguments)
Catch ex As Exception
exceptionLogging(ex, className, functionName)
End Try
End Sub

The executeProgram-funtion is:

''' <summary>
''' Führt ein Programm aus und gibt Rückmeldung, ob die Ausführung
erfolgreich war.
''' </summary>
''' <param name="programName">Programmname (für das Log)</param>
''' <param name="program">Programm mit Pfad</param>
''' <param name="arguments">Argumente / Parameter</param>
''' <param name="visible">true oder false, je nachdem ob das
Programm sichbar sein soll</param>
''' <param name="noWait">true oder false, je nachdem ob auf das
Programm gewartet werden soll</param>
''' <param name="skipAvailabilityCheck">true oder false, je
nachdem, ob die Verfügbarkeit des Programms überprüft werden soll</
param>
''' <param name="redirectFilename">Dateiname, wohin die Ausgabe
umgeleitet werden soll. Wenn leer, dann wird die Ausgabe nicht
umgeleitet.</param>
''' <returns>true oder false, je nachdem ob das Programm gestartet
werden konnte</returns>
''' <remarks></remarks>
Public Function executeProgram(ByVal programName As String, ByVal
program As String, Optional ByVal arguments As String = "", Optional
ByVal visible As Boolean = True, Optional ByVal noWait As Boolean =
False, Optional ByVal skipAvailabilityCheck As Boolean = False,
Optional ByVal redirectFilename As String = "") As Boolean
Dim functionName As String = "executeProgram"
Try
If Not skipAvailabilityCheck Then
If Not File.Exists(program) Then
log("Die Datei: '" & program & "' existiert
nicht", )
Dim myException As Exception =
Library.newException(className, functionName, "Die Datei: '" & program
& "' existiert nicht")
Throw myException
End If
End If

Dim theProcessStartInfo As New ProcessStartInfo(program,
arguments)

If visible = True Then
theProcessStartInfo.CreateNoWindow = False
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Normal
Else
theProcessStartInfo.CreateNoWindow = True
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Hidden
End If

If redirectFilename <"" Then
theProcessStartInfo.RedirectStandardOutput = True
theProcessStartInfo.UseShellExecute = False
End If

log("Starte '" & programName & "'", )
If arguments <"" Then
log("Aufruf: '" & program & " " & arguments & "'", )
Else
log("Aufruf: '" & program & "'", )
End If
Dim myProcess As New Process
myProcess.StartInfo = theProcessStartInfo
myProcess.Start()
log(programName & " gestartet", )

If redirectFilename = "" Then
If noWait Then
log("Auf die Beendigung von " & programName & "
wird nicht gewartet", )
Else
log(programName & " geschlossen", )
End If
End If
If redirectFilename <"" Then
Dim myFileInfo As New FileInfo(redirectFilename)
If Not Directory.Exists(myFileInfo.DirectoryName) Then

Directory.CreateDirectory(myFileInfo.DirectoryName )
End If

Dim output As String =
myProcess.StandardOutput.ReadToEnd
output = output.Replace(vbLf, "")
output = output.Replace(vbCr, vbNewLine)

Dim myWriter As New StreamWriter(redirectFilename,
False)
myWriter.Write(output)
myWriter.Close()

log(programName & " geschlossen", )
End If

Return True

Catch ex As Exception
exceptionLogging(ex, className, functionName)
Dim myException As Exception =
Library.newException(className, functionName, ex.Message)
Throw myException
End Try
End Function
Jan 14 '08 #1
1 2042
On Jan 14, 12:28 pm, sewid <sebastian.widm...@gmail.comwrote:
Hi there!

I've got a problem with no solution, I hope you might help me.

I am writing a small tool with many buttons. Every button starts a
thread and this thread starts something else, in the example posted
below, the hardware configuration dialog. My problem is, that
sometimes when I close the executed program / application / dialog, my
program is displayed in background. When I execute the taskmanager,
everything works fine, but when I execute e.g. the hardware
configuration dialog, this behaviour occurs. Can somebody tell me why
and how to avoid this? (I don't want a topMost-application).

Using the shell()-command leads to the same behaviour.

Thanks in advance, best regards,
Sebastian

The button-click-action is:

Private Sub butSettingsHardware_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
butSettingsHardware.Click
Dim functionName As String = "butSettingsHardware_Click"
Try
Dim myThread As New Thread(AddressOf
threadOpenSettingsHardware)
myThread.Start()
Catch ex As Exception
exceptionLogging(ex, className, functionName)
End Try
End Sub

The started thread is:
''' <summary>
''' Öffnet die Hardware-Einstellungen
''' </summary>
''' <remarks></remarks>
Private Sub threadOpenSettingsHardware()
Dim functionName As String = "threadOpenSettingsHardware"
Try
Dim programName As String = "Display-Einstellungen"
Dim program As String = "rundll32.exe"
Dim arguments As String = "shell32.dll,Control_RunDLL
sysdm.cpl,,2"

executeProgram(programName, program, arguments)
Catch ex As Exception
exceptionLogging(ex, className, functionName)
End Try
End Sub

The executeProgram-funtion is:

''' <summary>
''' Führt ein Programm aus und gibt Rückmeldung, ob die Ausführung
erfolgreich war.
''' </summary>
''' <param name="programName">Programmname (für das Log)</param>
''' <param name="program">Programm mit Pfad</param>
''' <param name="arguments">Argumente / Parameter</param>
''' <param name="visible">true oder false, je nachdem ob das
Programm sichbar sein soll</param>
''' <param name="noWait">true oder false, je nachdem ob auf das
Programm gewartet werden soll</param>
''' <param name="skipAvailabilityCheck">true oder false, je
nachdem, ob die Verfügbarkeit des Programms überprüft werden soll</
param>
''' <param name="redirectFilename">Dateiname, wohin die Ausgabe
umgeleitet werden soll. Wenn leer, dann wird die Ausgabe nicht
umgeleitet.</param>
''' <returns>true oder false, je nachdem ob das Programm gestartet
werden konnte</returns>
''' <remarks></remarks>
Public Function executeProgram(ByVal programName As String, ByVal
program As String, Optional ByVal arguments As String = "", Optional
ByVal visible As Boolean = True, Optional ByVal noWait As Boolean =
False, Optional ByVal skipAvailabilityCheck As Boolean = False,
Optional ByVal redirectFilename As String = "") As Boolean
Dim functionName As String = "executeProgram"
Try
If Not skipAvailabilityCheck Then
If Not File.Exists(program) Then
log("Die Datei: '" & program & "' existiert
nicht", )
Dim myException As Exception =
Library.newException(className, functionName, "Die Datei: '" & program
& "' existiert nicht")
Throw myException
End If
End If

Dim theProcessStartInfo As New ProcessStartInfo(program,
arguments)

If visible = True Then
theProcessStartInfo.CreateNoWindow = False
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Normal
Else
theProcessStartInfo.CreateNoWindow = True
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Hidden
End If

If redirectFilename <"" Then
theProcessStartInfo.RedirectStandardOutput = True
theProcessStartInfo.UseShellExecute = False
End If

log("Starte '" & programName & "'", )
If arguments <"" Then
log("Aufruf: '" & program & " " & arguments & "'", )
Else
log("Aufruf: '" & program & "'", )
End If
Dim myProcess As New Process
myProcess.StartInfo = theProcessStartInfo
myProcess.Start()
log(programName & " gestartet", )

If redirectFilename = "" Then
If noWait Then
log("Auf die Beendigung von " & programName & "
wird nicht gewartet", )
Else
log(programName & " geschlossen", )
End If
End If

If redirectFilename <"" Then
Dim myFileInfo As New FileInfo(redirectFilename)
If Not Directory.Exists(myFileInfo.DirectoryName) Then

Directory.CreateDirectory(myFileInfo.DirectoryName )
End If

Dim output As String =
myProcess.StandardOutput.ReadToEnd
output = output.Replace(vbLf, "")
output = output.Replace(vbCr, vbNewLine)

Dim myWriter As New StreamWriter(redirectFilename,
False)
myWriter.Write(output)
myWriter.Close()

log(programName & " geschlossen", )
End If

Return True

Catch ex As Exception
exceptionLogging(ex, className, functionName)
Dim myException As Exception =
Library.newException(className, functionName, ex.Message)
Throw myException
End Try
End Function
In your code, one thing i paid attention which may be the reason:

If visible = True Then
theProcessStartInfo.CreateNoWindow = False
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Normal
Else
theProcessStartInfo.CreateNoWindow = True
theProcessStartInfo.WindowStyle =
ProcessWindowStyle.Hidden

' Here you hide the app's window's style maybe it's still running but
in hidden window state, so i recommend to change it to "normal" if you
reproduce the same issue.

End If

Meanwhile, i was wondering similiar thing to this which forced me to
think why an app is still running on background althoýugh it seems
off, then i awared of the forms were "hidden" by "me.hide", after
closing it gone away from background ...
Jan 14 '08 #2

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

Similar topics

6
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
10
by: Ricky W. Hunt | last post by:
I have written a close routine to handle an "Exit" button to close the application properly. How do I make sure this gets executed if the user closes it another way (by pressing the "X" in the...
3
by: Amar | last post by:
I have a abc.PRG file in visual foxpro 8.0. I can run this file using visual foxpro environment and it creates a table X.dbf in the same folder where this program file is and populates some data...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
2
by: polocar | last post by:
Hi, suppose that you have a C# form with two buttons, that are the classical "btnOk" and "btnCancel" (besides them, of course in the form there can be many other controls). When the user clicks...
1
by: CL4life | last post by:
I have the following problem: a program, located on drive a known drive (for example lets say drive C:) needs to execute a program on an unknown different drive (a USB device which doesn't have the...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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...

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.