473,379 Members | 1,386 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,379 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 2025
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...
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
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.