FileSystemWatcher - New Form Hanging

G

Guest

Hi,

I have a problem when I try to open a new form with the Changed event
(FileSystemWatcher) : the form hangs just after the paint. But I use the same
function (OpenFormPerform) to open a new form when I click on the Button1 and
it works fine. I think that it's a problem with thread or applicationContext.
I can use Application.Run(new Form) to put the new form in the message loop
but the application is suspended after the Application.Run() statement.

Thx for your help.

Public Class FrmPrinc
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(88, 48)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'FrmPrinc
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "FrmPrinc"
Me.Text = "FrmPrinc"
Me.ResumeLayout(False)

End Sub

#End Region

Private WithEvents FSW As System.IO.FileSystemWatcher
Private Delegate Sub OpenForm()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
OpenFormPerform()
End Sub

Private Sub FrmPrinc_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FSW = New System.IO.FileSystemWatcher
FSW.Path = Environment.GetEnvironmentVariable("USERPROFILE")
FSW.NotifyFilter = IO.NotifyFilters.CreationTime Or
IO.NotifyFilters.DirectoryName Or IO.NotifyFilters.FileName Or
IO.NotifyFilters.LastWrite
FSW.Filter = "BrowserIN.TXT"
FSW.EnableRaisingEvents = True
End Sub

Private Sub OpenFormPerform()
Dim myForm As New Form
myForm.Controls.Add(New TextBox)
myForm.Show()
MessageBox.Show("OK")
End Sub

Private Sub FSW_Changed(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FSW.Changed
OpenFormPerform()
End Sub

End Class
 
G

Guest

Any idea ?

"Frederic H" a écrit :
Hi,

I have a problem when I try to open a new form with the Changed event
(FileSystemWatcher) : the form hangs just after the paint. But I use the same
function (OpenFormPerform) to open a new form when I click on the Button1 and
it works fine. I think that it's a problem with thread or applicationContext.
I can use Application.Run(new Form) to put the new form in the message loop
but the application is suspended after the Application.Run() statement.

Thx for your help.

Public Class FrmPrinc
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(88, 48)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'FrmPrinc
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "FrmPrinc"
Me.Text = "FrmPrinc"
Me.ResumeLayout(False)

End Sub

#End Region

Private WithEvents FSW As System.IO.FileSystemWatcher
Private Delegate Sub OpenForm()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
OpenFormPerform()
End Sub

Private Sub FrmPrinc_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FSW = New System.IO.FileSystemWatcher
FSW.Path = Environment.GetEnvironmentVariable("USERPROFILE")
FSW.NotifyFilter = IO.NotifyFilters.CreationTime Or
IO.NotifyFilters.DirectoryName Or IO.NotifyFilters.FileName Or
IO.NotifyFilters.LastWrite
FSW.Filter = "BrowserIN.TXT"
FSW.EnableRaisingEvents = True
End Sub

Private Sub OpenFormPerform()
Dim myForm As New Form
myForm.Controls.Add(New TextBox)
myForm.Show()
MessageBox.Show("OK")
End Sub

Private Sub FSW_Changed(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FSW.Changed
OpenFormPerform()
End Sub

End Class
 

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

Top