Forms question for a non-windows application

Using Visual Studio 2005 (my first app using .net, btw - but been using VB6 for 5 + years)

There are windows forms that are instantiated through events thrown by FileSystemWatcher class.

The issue is with giving scope to the instatiated form.

Except, the form is frozen! I can't do anything to it:

Code is as follows (irrelevant code excluded)

Public f As frmMyForm

FileSystemWatcher1_OnCreated()

   f = new frmMyForm 
   f.Show()    '<<< It shows, but its like its frozen!
  
End Sub   
   

I know theres something i'm doing wrong - but not sure what I need to do.
Is it a bad idea to launch a form through the OnCreated event of the FileSystemWatcher class

I'll bet it is, but i'm not sure.

if so, what should I do to instatiate a NEW FORM everytime OnCreated event is called

Help..

Thanks
Eric


Answer this question

Forms question for a non-windows application

  • freeflyr

    Hi,

    All of this is done in a public module (modMain.vb - has the entry point Main method)

    The application type is non-windows application.

    So implementation of the FileSystemWatcher is all in code. For example:

    Public WithEvents fsw As FileSystemWatcher

    The form I need to instantiate is Public. Like this:

    Public frmInstance as MyForm

    In the withevents event "fsw_OnCreated" (fired when a file is created in the watched directory), the form instance is set to a new form. Like this:

    fsw_OnCreated()

       frmInstance = new MyForm 

       frmInstance.Show

    Exit Sub

    What "i think" is happening, is the form is being instantiated - but because this isnt a Windows application (its actually a ServiceController app that does everything from the Main() sub), code execution is leaving the form frozen.

    Do you think I need to handle this through Thread classes For some reason, I thought instantiating a form would create the needed thread. But because everything is in classes, or because this isnt a windows application, threads have to be hard coded

    Appreciate the help,
    Eric






  • ollertoncj

    Apply the <STAThread()> attribute to the Main() method.

    This is already done in a Windows Forms project, but in a console application you must add it manually.

    Moreover, the main form of the application has to be started with Application.Run(form) to initiate the message loop. The form.Show() method can be used to open additional forms.

    Good luck!

    Jordan Jossifov

  • Sponchiz

    thanks for your reply.

    i couldnt get it to work, but I did come up with an alternative: msgbox works fine though it suspends the Created event of the FileSystemWatcher class.

    ive also noted where the FileSystemWatcher class is not so reliable so i'll be switching to an alternative solution for now (old fashioned polling with a timer)

    thanks again,
    Eric

  • Vinu_P

    Hi!
    I've been with VB6 2 years...

    I don't know why it doesn't work, it works just fine for me.

    Can you be more specific.
    Are you instantinating the same form the FileSystemWather Object is declared in
    Are you doing stuff in the Load event of the Form called frmMyForm

    Thanks!

  • Forms question for a non-windows application