# .NET and More > WPF, WCF, WF >  how to detect if window is already opened or not

## yoosufshanij

how to detect if a window is already opened or not from another window in wpf

----------


## chris128

If you mean a window within your application, then you can loop through the Application.Current.Windows collection and if your window is in there then an instance of it has been created - you would need to check whether or not this instance is actually visible if you wanted to be 100&#37; sure whether or not the window was "open".

E.g:

vb Code:
For Each OpenWindow As Window In Application.Current.Windows
            If OpenWindow.Name = "MyWindow" AndAlso OpenWindow.IsVisible Then
                MessageBox.Show("Found the window!")
            End If
Next

If you mean an external window (belonging to another program) then you will need to use Windows APIs, such as FindWindowEx.

----------


## yoosufshanij

Thanx a ton for the quick reply.....that worked very fine for me....

I need one more advise from your side.
is it possible to reload a window if found opened?

----------


## chris128

If by "reload" you just mean close it and create a new instance of it then yeah, it would be something like this:


vb Code:
For Each OpenWindow As Window In Application.Current.Windows
            If OpenWindow.Name = "MyWindow" AndAlso OpenWindow.IsVisible Then
                OpenWindow.Close
                Dim NewMyWindow As New MyWindow
                NewMyWindow.Show()
            End If
Next

----------


## yoosufshanij

Thank u very much......

----------

