How to tell what other forms are opened.

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

I have an application with a menu system which creates a new thread when a
menu item is selected - some of these other threads may open a form for user
interaction.

Before the menu system is closed, I want to check that no other forms are
open - on any thread. Is there a way of checking for this easily? At
the moment, I'm not keeping track of new threads that I create ie I create
the new thread using code similar to as follows:

private sub RunMenu
dim obj as new myclass
dim t as new threading.thread(addressof obj.subroutinename)
t.start
end sub

How can I do this?

Thanks in advance
Simon
 
A very simple example:

Dim frm as Form1

If Not (frm Is Nothing) Then
MessageBox.Show("Form Exists")
Else
frm = new Form1
frm.ShowDialog()
End If

Crouchie1998
BA (HONS) MCP MCSE
 
Thanx for that.. Perhaps I should have explained better.

The menu system I have works on an XML file that contains the menu items,
along with dll names, class names and entry points - I create the object
through reflection and then start up a new thread to call it. I don't
keep track of the threads after I've started them off.

What I really want to do is know whether any forms started by these threads
are currently still running before I close the menu system down - i.e I
don't want the menu system closed whilst the application is running.

Maybe I should be searching for threads rather than forms?

Regards
Simon
 
Hi Simon,

Herez a thought -

When your threads create a form you could add it to a collection and on
closing the form remove it from the collection. So your collection would have
a list of open forms and you could iterate the collection to see if it has
any forms before closing the app.

VB.NET does not have an inbuilt Forms collection, but you could create a
class that behaves like a collection. Check out this link for some sample
code for the same.

http://www.dotnet247.com/247reference/msgs/21/107856.aspx

HTH
 
Sarika

Thanks for the thought, whilst this would be a little re-engineering of my
application to get working, I think I might be able to do the same with the
threads that I am creating - If I add each thread to a collection as I start
it up, then I can iterate through the collection at a later point and check
to see that all the threads have exited?

Regards
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top