Re: Filewatch saga continues
- From: "Tom Leylan" <tleylan@xxxxxxxxxx>
- Date: Sun, 14 Jan 2007 13:40:33 -0500
"Rudy" <Rudy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4D99291A-7C27-403D-95DE-0BEA355F8704@xxxxxxxxxxxxxxxx
For this form, ShowDialog wouldn't work. I have values that are taken
from
other forms, and populated into this one. I also have several connections
going on to SQL . The form is only up for 15 to 20 seconds, but there is
alot
of stuff goin on in that time frame. After the form is closed, it will be
opened again from the server application in about 30 seconds to a minute,
and
then the whole process starts. I'll do alot of testing on thsi, but I
think
for this need, this is the way to go.
Rudy:
It was trickier than I thought due in part (in so far as I can tell) to the
thread-safe features added to VS2005. Starting from here
http://msdn2.microsoft.com/en-us/library/ms171728.aspx I managed to create a
pop-up (non-modal) window that displays "file created" in a label which then
disappears when a set number of seconds elapses.
I might be able to cut enough code in to a reply to make it make sense
without boring everybody... let's see.
Public Class <your main form>
Private pop As PopUp
Private poptimer As System.Windows.Forms.Timer
Delegate Sub PopCallback()
Private WithEvents worker1 As BackgroundWorker
Public NKWatch As FileSystemWatcher
PopUp is a form which will display, poptimer is a timer to make it go away,
PopCallback is used by the NKWatch event handler worker1 is a
BackgroundWorker (per the instructions found on the MSDN site) and you know
about NKWatch.
Inside <your main form> initialization add the following. Notice I've only
set up a single pop-up form. If you need more than one you'll have to do a
bit more work. In any case this pop is ready for use but not visible until
a file is detected. I've set the timer to close it after 2 seconds.
pop = New PopUp
With pop
.Owner = Me
.TopMost = True
.Visible = False
End With
poptimer = New System.Windows.Forms.Timer
With poptimer
.Interval = 2000
.Enabled = False
End With
AddHandler poptimer.Tick, AddressOf PopHandler
worker1 = New BackgroundWorker
NKWatch = New FileSystemWatcher
With NKWatch
.Path = "C:\"
.Filter = "*.txt"
.IncludeSubdirectories = False
.EnableRaisingEvents = True
End With
AddHandler NKWatch.Created, AddressOf NKWatch_Created
You already have the event handler so simply add the code within this.
Public Sub NKWatch_Created(ByVal sender As Object, ByVal e As
FileSystemEventArgs)
Me.worker1.RunWorkerAsync()
End Sub
Add this event handler which the article describes will be called when the
RunWorker completed event is called.
Private Sub PopWorkerCompleted(ByVal sender As Object, ByVal e As
RunWorkerCompletedEventArgs) Handles worker1.RunWorkerCompleted
Dim p As New PopCallback(AddressOf PopShow)
Me.Invoke(p, New Object() {})
End Sub
Add PopShow to make the popup window appear and PopHandler to make it
disappear.
Private Sub PopShow()
pop.Visible = True
poptimer.Start()
End Sub
Private Sub PopHandler(ByVal myObject As Object, ByVal myEventArgs As
EventArgs)
pop.Visible = False
poptimer.Stop()
End Sub
Clearly you'll have to futz with it somewhat and I've mixed my AddHandler
and Handles syntax (I prefer AddHandler) but hopefully this points you in
the right direction.
Tom
.
- Follow-Ups:
- Re: Filewatch saga continues
- From: Rudy
- Re: Filewatch saga continues
- References:
- Re: Filewatch saga continues
- From: Tom Leylan
- Re: Filewatch saga continues
- From: Rudy
- Re: Filewatch saga continues
- From: Tom Leylan
- Re: Filewatch saga continues
- From: Rudy
- Re: Filewatch saga continues
- From: Rudy
- Re: Filewatch saga continues
- From: Tom Leylan
- Re: Filewatch saga continues
- From: Rudy
- Re: Filewatch saga continues
- Prev by Date: Re: How to convert binary to ASCII
- Next by Date: How to give each user full rights to registry keys ?
- Previous by thread: Re: Filewatch saga continues
- Next by thread: Re: Filewatch saga continues
- Index(es):
Relevant Pages
|