Re: Filewatch saga continues



"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


.



Relevant Pages

  • Re: Filewatch saga continues
    ... Private WithEvents worker1 As BackgroundWorker ... AddHandler NKWatch.Created, AddressOf NKWatch_Created ... You already have the event handler so simply add the code within this. ... Private Sub PopWorkerCompleted(ByVal sender As Object, ...
    (microsoft.public.dotnet.general)
  • dynamic button creation with event handling?
    ... How can I dynamically create buttons and wire them to an event handler? ... part of the codebehind using AddHandler, but I can't use AddHandler with a ... Protected WithEvents btnEditIdent As System.Web.UI.WebControls.Button ... Private Sub Page_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Addhandler help
    ... I am adding image buttons dynamically and I need to add event handler when ... AddHandler LnkImage.Command, AddressOf NewIbnCommandEvent() ... Private Sub NewIbnCommandEvent(ByVal sender As System.Object, ... I do not know what to put in between the AddHandler LnkImage.Command, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Event handler not firing
    ... In the event handler I rebuild the table adding event handlers again ... Private Sub Page_Load(ByVal sender As System.Object, ... private sub buildpage() ... addHandler myButton.Click, addressOf buttonClickHandler ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to capture a Mailitem Event
    ... You would need to put the cursor in the Initialize_Handler() procedure and press F5 to run the code to initialize the event handler manually to test the code. ... Private Sub col_NewInspector ... It would only handle 1 open mail item at a time, and it would only handle mail items. ...
    (microsoft.public.outlook.program_vba)