I need to check if any "File Download" dialogs are open, which means I am downloading something so that my program will not attempt to download 2 files at the same time.

I have no clue on how to do this and need help.

Thank you.

Check My.Application.OpenForms collection:

Public Function FormsRunning(ByVal FormName As String) As Integer
  ' Return number of forms with name FormName in this application
  Dim Count As Integer
  Dim i As Integer

  Count = 0
  For i = 0 To My.Application.OpenForms.Count - 1
    If My.Application.OpenForms.Item(i).Text = FormName Then
      Count += 1
    End If
  Next i
  Return Count

End Function

Now you can test if the form should be opened:

If FormsRunning("File Download") = 0 Then
  ' Open your form
End If

The File Download dialog will not be a download from my program. For example it could be a download from rapidshare. How can i check if that is running?

Ok. But you do know that the title is "File Download"? I believe that then the code from my blog post is suitable for your purpose.

Public Function ProcessesRunning(ByVal ProcessName As String) As Integer
   Return Process.GetProcessesByName(ProcessName).GetUpperBound(0) + 1
   Return 0
 End Try

End Function

and check

If ProcessesRunning("File Download") > 1 Then
 ' Second instance was started
End If

When processes running "File Download" is > 1 then it means that the download is not running?

i dont know what is going on but it always returns 0 which means the download is not running !???

maybe in the process name i have to give the exact name? e.g("File Download- rapidsharre.part1.app")

Hi! Sorry for inadequate explanation. I'll give you an example with Notepad:

If ProcessesRunning("Notepad") = 0 Then
 ' Notepad is not running
End If
If ProcessesRunning("Notepad") = 1 Then
 ' Notepad is running (one instance)
End If
If ProcessesRunning("Notepad") > 1 Then
 ' User has started more than one Notepad intances
End If

And the process name in Task Manager is Notepad.exe.
Start one download and check from Task Manager/Processess how it's displayed in there. You should find it from there, just like "Notepad.exe"->"Notepad".

When processes running "File Download" is > 1 then it means that the download is not running?

No, it means that one download is running and the user has started a second (or third...) download, see the examples above.

And yes, it needs exact process name.

ok thank you...now you made it more clear...i'll check and let you know if it works for me :D

im having a hard time to figure out what i have to put in place of the "Notepad". could you possibly make a rapidshare download and see if you can find out how to check if the download dialog is running

Open the Task Manager, check which processes are running. Start download with RapidShare and re-check processes in Task Manager.
If I understand it right, "File Download" dialog comes from the browser (?). In that case you won't see it in the process list. For example, if you have two Firefox instances running, you'll see only one Firefox process. If this is the case, you'll have to use some other approach to check "File Download" dialog. What that would be, doesn't come in to mind straight away. But I'm sure there's some way to find out if you have "File Download" dialog open, it's just not a process like I assumed in the first place.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.