-
Jan 12th, 2021, 01:34 PM
#1
Thread Starter
Hyperactive Member
Another window doesnt popup though it should
Hi,
I am facing strange issue - when another app is not running and folder exists, it does not shown another form. However, if folder does not exists and app is running, it works fine. I prior thought that timers restarting policy is the issue, but its not since it works when folder does not exists.
2nd app only creates folder and removes it every 5 seconds.
another form is a form with close button that closes it.
Code:
Imports System.Net
Public Class my_program
Public Declare Auto Function FindWindowNullClassName Lib "user32.dll" Alias "FindWindow" (ByVal lpClassName As Integer, ByVal lpWindownName As String) As Integer
Dim Counter As Integer = 0
Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\") Then
Else
My.Computer.FileSystem.CreateDirectory("C:\directory.desc\")
End If
timer1.Interval = 15000 '15 sek
timer1.Start()
End Sub
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
If hWnd = 0 And Not My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
AnotherForm.Show()
Else
End If
End Sub
I dont see the problem since theres AND in my code i.e. both conditions are handled.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 12th, 2021, 02:22 PM
#2
Re: Another window doesnt popup though it should
If you want AnotherForm to show when the folder exists, why are you checking if it does exist in your If statement?
-
Jan 12th, 2021, 03:17 PM
#3
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
That does not matter how its written. if file exists or if not file exists
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 12th, 2021, 03:23 PM
#4
Re: Another window doesnt popup though it should
Originally Posted by VB.NET Developer
That does not matter how its written. if file exists or if not file exists
Good luck then.
-
Jan 12th, 2021, 04:06 PM
#5
Re: Another window doesnt popup though it should
No... both conditions are not handled...
Code:
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
If hWnd = 0 And Not My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
AnotherForm.Show()
Else
End If
End Sub
That handles one case... where the hWnd is 0 (ie the app is NOT running) and where the Directory does NOT exist ... BUT ... in your start up here:
Code:
Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\") Then
Else
My.Computer.FileSystem.CreateDirectory("C:\directory.desc\")
End If
you forced the directory to be created... so it will always exist....
You never handled the Else case in the Timer1_Tick event .... you have 4 possible outcomes:
hWnd = 0 and directory exists
hWnd = 0 and directory does not exist
hWnd <> 0 and directory exists
hWnd <> 0 and directory does not exist
You've only handled that second one... you haven't done anything to handle any of those other cases. But since you force the directory creation, you really only care about two outcomes:
hWnd = 0 and directory exists
hWnd <> 0 and directory exists
But you've still only handled the one possibility... and it isn't one of those two...
-tg
-
Jan 13th, 2021, 07:05 AM
#6
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
Beware,
its not the correct directory. The correct directory is C:\directory.desc\initial-check
No, the directory is periodically created and removed every 3 seconds - via another app with this code:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 3000
Timer1.Start
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
My.Computer.FileSystem.DeleteDirectory("C:\directory.desc\initial-check", FileIO.DeleteDirectoryOption.DeleteAllContents)
Else
My.Computer.FileSystem.CreateDirectory("C:\directory.desc\initial-check\")
End If
End Sub
The problem is, after a few seconds when folder is created and removed, AnotherForm is opened.
My current code:
Code:
Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 15000 '15 sek
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
If hWnd = 1 And My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
Else
AnotherForm.Show()
End If
You can try these codes yourself and you will see the behavior.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 16th, 2021, 12:59 PM
#7
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 16th, 2021, 01:28 PM
#8
Re: Another window doesnt popup though it should
The whole thing seems convoluted. You have a separate application that, every 3 seconds will either create this folder if it doesn't exist, or will delete the folder if it does. So every 3 seconds it goes from existing, to non-existing, to existing, to non-existing, ...
Then, every 15 seconds, this other application displays AnotherForm if hWnd != 1 Or the directory in question doesn't exist. Because the directory in question doesn't exist half of the time, I would expect AnotherForm to be displayed every other time that 15 second timer is ran, so every 30 seconds or so (with some variance as far as how closely the two timers are aligned).
I think the help you need is only going to happen if you explain, in detail what, exactly, you are trying to accomplish with this convoluted timer and folder stuff.
As it stands, I doubt anyone has a clue what your end goal is and therefore no specific coding help can be offered.
Good luck.
-
Jan 20th, 2021, 10:19 AM
#9
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 20th, 2021, 10:23 AM
#10
Re: Another window doesnt popup though it should
Originally Posted by VB.NET Developer
Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
Why? Is this a "because I can" sort of thing or are you actually trying to achieve something useful? If the latter, you should explain what that is because it's hard to imagine that there isn't a better way than what you describe.
-
Jan 20th, 2021, 10:45 AM
#11
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
I already explained what it is - I want to detect presence of my second app when both conditions are true. Enough explanation?
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 20th, 2021, 12:38 PM
#12
Re: Another window doesnt popup though it should
Originally Posted by VB.NET Developer
Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
Right. And yet, your second app keeps deleting and recreating that folder REPEATEDLY. So there will continuously be times that your first app finds the second app via window name, but the folder is missing.
And there's been no logical reason given for WHY you are doing any of this with timers, window handles, and folder recreation. And because I doubt that reason is forthcoming, I'm officially done with this thread.
Good luck.
-
Jan 20th, 2021, 01:31 PM
#13
Re: Another window doesnt popup though it should
You can check for a running process like this:-
Code:
'
If Process.GetProcessesByName("Notepad").Length > 0 Then
MessageBox.Show("Notepad is running!!")
End If
-
Jan 20th, 2021, 01:54 PM
#14
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
Sure, I know, but I solved this via window name instead of process name.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 20th, 2021, 07:05 PM
#15
Re: Another window doesnt popup though it should
Originally Posted by VB.NET Developer
I already explained what it is
Yes you did, but I didn't ask you "what". I asked you "why". You don't have to answer my question if you don't want to but I'm not interested in helping people to do the wrong thing so if you can't help me establish that what you want to do is the right thing, I won't be spending my time helping you to do it.
-
Jan 25th, 2021, 12:16 PM
#16
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
I want to build some kind of advanced process detector.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Feb 8th, 2021, 12:11 PM
#17
Thread Starter
Hyperactive Member
Re: Another window doesnt popup though it should
@jmcilhinney
Hope that is enough explanation what I want to do. Or am I wrong?
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|