473,216 Members | 1,937 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,216 software developers and data experts.

RaiseEvent not working

I have a program with a couple of long running processes that i'm calling on
a separate thread.

When the process is completed, I want to raise an event to tell the main
thread that it's done. I set it up this way...

Public Class frmLongRunningProcess

Public Enum Proc
ParseZipFiles = 0
TestZipFiles = 1
GetWebLinks = 2
SynchronizeDirs = 3
End Enum

Public Event Done(ByVal ProcDone As Proc)

Public Sub New(ByVal PerformProc As Proc, ByVal TargetList As ArrayList)
InitializeComponent()
With Me
.lblCount.Text = ""
.lblMsg.Text = ""
.lblTitle.Text = ""
.pb.Value = 0
.Show()
End With

Select Case PerformProc
Case Proc.TestZipFiles
ThreadPool.QueueUserWorkItem(AddressOf TestZipFiles, TargetList)
Case Proc.SynchronizeDirs
ThreadPool.QueueUserWorkItem(AddressOf SynchronizeDirs, TargetList)
End Select
End Sub

Private Sub TestZipFiles(ByVal state As Object)
'Perform Long Running Process..
RaiseEvent Done(Proc.TestZipFiles)
CloseForm()
End Sub
Private Sub SynchronizeDirs(ByVal State As Object)
'Perform Long Running Process..
RaiseEvent Done(Proc.SynchronizeDirs)
CloseForm()
End Sub

End Class

Then, in my main program, I have the following code:

Dim WithEvents LongRunProc As frmLongRunningProcess
Private Sub LongRunProc_Done(ByVal e As frmLongRunningProcess.Proc) Handles
LongRunProc.Done
MsgBox(e.ToString)
End Sub

When I run the "TestZipFiles" process, the event gets raised and I see the
expected MessageBox. But When I run the "SynchronizeDirs" process, the event
doesn't get raised. If I change the "RaiseEvent" line in the "TestZipFiles"
routine to "Proc.SynchronizeDirs", the event gets raised as expected. It is
only the "SynchronizeDirs" routine that does not raise the event. Both
routines close the form as expected. Since it might help to see all the code
in that routine, i'll post it below:

Private Sub SynchronizeDirs(ByVal State As Object)
Dim TargetList As ArrayList = State
UpdateProgressBar(0)
SetTitle("Adding new files to list...")
For Each fmdir As String In TargetList
UpdateProgressBar(0)
Dim di As New DirectoryInfo(fmdir)
SetMsg(fmdir)
Dim dif() As FileInfo = di.GetFiles("*.zip",
SearchOption.TopDirectoryOnly)
SetProgressBarMax(dif.Length)
'Make sure each file in the directory is in the database.
For i As Integer = 0 To dif.Length - 1
Dim fi As FileInfo = dif(i)
SetMsg(fmdir & "\" & fi.Name)
UpdateProgressBar(i + 1)
Dim cmd As String = "SELECT COUNT(*) FROM FMFiles WHERE
[Filename] = '" & fi.Name & "' AND [Directory] = '" & fmdir & "'"
If MDBScalar(cmd) 0 Then Continue For
cmd = "INSERT INTO FMFiles (Filename,[FileSize (MB)],Directory)
VALUES (" & _
"'" & fi.Name & "','" &
Double.Parse(System.Math.Round((fi.Length / 1024) / 1000, 2),
CI.NumberFormat) & "'," & _
"'" & fmdir & "')"
MDBNonquery(cmd)
Next
Next
UpdateProgressBar(0)
SetTitle("Removing deleted files from list...")
'Kill any database entries that aren't in a directory
Dim dt As DataTable = MDBQuery("SELECT ID,Filename,Directory FROM
FMFiles")
SetProgressBarMax(dt.Rows.Count)
UpdateProgressBar(0)
For Each r As DataRow In dt.Rows
IncrementProgressBar()
SetMsg(r.Item("Directory") & "\" & r.Item("Filename").ToString)
If File.Exists(r.Item("Directory").ToString & "\" &
r.Item("Filename").ToString) = False Then
MDBNonquery("DELETE FROM FMFiles WHERE ID=" &
r.Item("ID").ToString)
End If
Next
RaiseEvent Done(Proc.SynchronizeDirs)
CloseForm()
End Sub
May 20 '07 #1
1 2018
Nevermind. Figured it out.

It would help if I used the actual variable I setup using WithEvents instead
of instinctively doing a "dim x as new LongProc".
May 20 '07 #2

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

Similar topics

1
by: Guille | last post by:
Hi all! I'm having some weird behaviour in a .NET application i'm developing. I'll try to explain: I've created a Class that wraps an asynchronous socket. When connect callback is called, i...
8
by: Nicolas | last post by:
How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot. ******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher(); public delegate void...
2
by: Carl tam | last post by:
Hi everyone, I got a quite interesting problem myself and got stuck. I have an aspx page with a windows user control with it. in the Windows Control. I have a RaiseEvent statement, say...
2
by: Lim | last post by:
I've developed a program that raise an event. This program works fine on a Windows 2000 Professional PC. However when I try to run the program on a Windos XP Professional PC, the program will not...
2
by: Vitoto | last post by:
Hi guys, i Need fix this issue. My VB.Net is Anticheat Program, And Server Game is working in port 2346. I Need Thread looking when My computer Established Connection to Any IP in Port 2346...
3
by: Adam | last post by:
I cannot figure out what I'm doing wrong, can someone shed some light on this for me? I have the following code inside a working user control (MyControl): Public Event SubmitClick(ByVal sender...
2
by: dmoonme | last post by:
I'm trying to rename some files in a directory. Pretty basic stuff - renaming the files works fine but the problem I have is updated the text in textbox. All I want to do is appendtext to a...
7
by: Onokiyo | last post by:
Hello, I have the code below and somehow the message from RaiseEvent doesn't pop up at all. Can someone help me please? '------CODE '------/form1.vb/VB2005/Framework20--------- Imports...
2
by: ffa | last post by:
I have a number of classes that declare a public Event called RefreshData: Public Class Client Implements INotifyPropertyChanged Implements IDisposable Implements IDataErrorInfo Public...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.