473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

FileSystemWatcher - New Form Hanging

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

Jan 30 '06 #1
1 2729
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

Feb 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
Hi, I've been developing an application in VB.NET that uses the FileSystemWatcher and a popup notification in order to tell me when files have been downloaded. The FileSystemWatcher code in...
2
by: Sacha Korell | last post by:
I need to set up a FileSystemWatcher in my web application (to automatically process uploaded files) and I'm trying to decide where to set it up. I would like to keep it within the web app, but it...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
12
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
1
by: teslar91 | last post by:
I've been learning VB.NET for the past few weeks. One of the problems I've run into is difficulties updating controls in events from certain components, such as the FileSystemWatcher, that raise...
4
by: hooksie2 | last post by:
Hi, I am trying to use FileSystemWatcher to watch a log file which is written to via a 3rd party app and display the log in listbox on a form. The FileSystemWatch seems to work okay but I get...
15
by: Angelo | last post by:
Hi all, I'm using a FileSystemWatcher to monitor a directory. I want the FSW to pop up my already instantiated but invisible form. However, I'm running into some problems with this. 1) In...
4
by: Andrus | last post by:
To reporoduce, run the code. Observed: Form is shown Expected: message box should displayed. How to fix ? Andrus.
1
by: Lila Godel | last post by:
My VB.NET 2008 application is setup with a Sub Main and no forms. At run time a NotifyIcon is created with one context menu choice (Close which terminates app). I have no trouble running the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.