Re: Filewatch saga continues



I have to say that I doubt your solution is the best way but there is no way
to tell unless we know what are you ultimately trying to do. What is point
of the pop-up form?

Again you're creating a temporary form (with a very short lifespan) and
displaying it non-modally. Is it supposed to take over for the main form?
Try this and see if some sort of dialog window would suit your needs.
Obviously you can fancy up the form but this demonstrates it can display
one.

Public Sub NKWatch_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs)

Dim frm As Form = New Form()
With frm
.Text = "File Created"
.ShowDialog()
End With

End Sub


"Rudy" <Rudy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C14BF363-62F2-4DBF-B56D-9814BB3D8529@xxxxxxxxxxxxxxxx
Hi Guys!

OK. So I think I got it to work.

Public Sub NKWatch_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim frmFirst As New Form1

frmFirst.Show()
Application.Run(FrmFirst)
End Sub
End Class
My question is this the best way. The form in question will only be up
for
15 -20 seconds. The the user quits out. It seems to work great! I just
want
to make sure I might not get in some kind of issue down the line.

Thanks for all your help!
Rudy

Ta


"Rudy" wrote:

Hi Tom!

I took out the hide, no change. With out the application.doevents, my
screen comes up white. But you say it works on yours? Are you running
2003
or 2005. Could it be my application of Visual Studio. It's been on this
workstation since 2004.

What do you think?

Rudy

"Tom Leylan" wrote:

But if everything else is working fine then the only thing left is the
form
right?

I just cut and pasted the code and had it out "file created" to the
immediate window and it works. So try not hiding "me" and see if the
form
isn't sitting there waiting for you to do something. The
Application.DoEvents() isn't doing anything as far as I can tell
either.
I'm still quite certain your program is running you just can't see the
form
because you've hidden it. frmFirst doesn't have focus and it's
destroyed
immediately.



"Rudy" <Rudy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B4C18D95-2798-43EC-B2CB-C65CA390EBB1@xxxxxxxxxxxxxxxx
Hi Tom!

Thnks for the suggestions. I did make sure my watch works properly,
but
having a s simple message box displayed. So I'm good there. I did
try and
create a click event on the client ap, and open up the second form,
and
that
works fine. Iknow the form is locked up, because after a few
seconds, I
get
a non-responding on the window on my form. When I try to debug it, it
doesnt
stop anywhere. Even when I put breka points, at the form load of the
form
2,
form 1 and the file wacther. And to make things more intersting,
after I
get
the window that ask if I want to stop this program, do you want to
send it
Microsoft. I get a meesage form CS 2003 that says "There is no source
code
avaiable for the current location"

So I'm not sure sure where to look. I wrote this simple app,
eleminating
everything elses in my real program. I hope if I can get this to
work, I
might be able to fix my real application.

Any other thoughts?

Thanks!
Rudy

"Tom Leylan" wrote:

There are a couple of suggestions I would like to offer. The first
is
(when
you're testing things that don't work) is to eliminate the parts
that
don't
(or probably don't) impact the problem. You could for instance
still see
the problem even if you eliminate the "server app" from the
equation.
You
can simply copy a file into the folder and that will work as well.
The
reason is that you're trying to narrow things down, the more pieces
involved
the harder that will be.

And don't create and show a form when you're not certain the watcher
is
working. Again you can output a simple message "I see it" to an
output
window and reduce the number of suspicious spots even more.

The next suggestion is to use the debugger. What is your client
application
doing when you think it has locked up? What do you want it to do?
If
I'm
not mistaken you'll find that your client app is running but without
a
form
on display. You are hiding the main form and showing a "Form1" (you
should
rename that class) but it won't retain the focus the way you've
written
it.
It closes, the event handler is exited and frmFirst goes out of
scope and
is
destroyed.

I don't believe it has locked up I believe you can't see that it is
still
running.

Tom


"Rudy" <Rudy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CCFE8EAD-37D7-4E2F-B7C9-B29D593670E2@xxxxxxxxxxxxxxxx
Hello!

I posted this problem earlier. I wrote a quick test project, and
I
still
have the same problem. So I'm sure it's something in my code that
I'm
not
writing correctly.
Basicly I'm creating a file with abutton click from one
application.
The
other application has a file watch setup, when it see the newly
created
file,
it is prompted to open up a new form. But it locks up atn the
very end
of
opening up the form.

Take a look at my code, what am I doing wrong? Or is there a
better
way
of
doing this? Thanks!

Rudy
SERVER APPLICATION
<BEGIN CODE>
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form

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

Dim TimeStamp As String = Guid.NewGuid.GetHashCode
Dim TempFile As String = "C:\test\watch"
Dim ext As String = ".out"
Dim FileName As String = TempFile & TimeStamp & ext
Dim fs As New FileStream(FileName, FileMode.Create)
fs.Close()
End Sub

End Class
CLIENT APPLICATION with from that has watch process
<BEGIN CODE>
Imports System.IO
Public Class Form2
Inherits System.Windows.Forms.Form

Public NKWatch As New FileSystemWatcher

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles MyBase.Load

AddHandler NKWatch.Created, AddressOf NKWatch_Created
Try
NKWatch.Path = "C:\test\watch"
NKWatch.Filter = "*.out"
NKWatch.IncludeSubdirectories = False
NKWatch.EnableRaisingEvents = True
Catch ERR As Exception
MessageBox.Show(ERR.Message)
End Try
End Sub

Public Sub NKWatch_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim frmFirst As New Form1
Me.Hide()
frmFirst.Show()
Application.DoEvents()
End Sub
End Class








.



Relevant Pages