DevTrain Startseite Advanced Developers Conference vom 14.-15. Februar 2011  
  
  
SUCHEN:  
ARTIKEL ONLINE: 525   

Kategorien
.NET
Datenbanken
Web
XML

Allgemein
Camp
Foren
Events
Persönliche Einstellungen
Registrieren
Prämien Shop
Kontakt
Impressum
Über DevTrain

Autoren



 

Forum: VB.NET | Thema: How to know that a thread has finshed. | Von: Theo Driemann ( 15.04.2006 17:45)

When the thread has finished I suppose to get the message "MsgBox("Thread has finished.")" but nothing happens. Is there anybody who knows where I made the mistake ?


Private Sub but_StartBrowsing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles but_StartBrowsing.Click

....

THR_Browse = New Threading.Thread(AddressOf BFMF.BrowseForFiles)

BFMF.dir = dirInfo
BFMF.exTensions = exTensions
BFMF.AL_MediaFileAndPath = AL_MediaFileAndPath

THR_Browse.Start()

End Sub


Private WithEvents evBFMF As clsFilesAndFolders


Sub BFMFeventHandler(ByVal AL_MediaFileAndPath As ArrayList) Handles evBFMF.ThreadComplete

MsgBox("Thread has finished.")

End Sub


Public Class clsFilesAndFolders

Public Event ThreadComplete(ByVal AL_MediaFileAndPath As ArrayList)

Public AL_MediaFileAndPath
Public exTensions
Public dir

Public Sub BrowseForFiles()
'This function search for files with a specific extension.
'dir : Directory path as directory.info.
'extensions() : Extension(s) where you are looking for.
'AL_MediaFileAndPath : Array list where the results are stored.

Dim subDir As IO.DirectoryInfo
Dim file As IO.FileInfo

Try

RaiseEvent ThreadComplete(AL_MediaFileAndPath)
For Each Filter As String In exTensions 'S1#. Loop through all extensions.
For Each file In dir.GetFiles("*." + Filter)

If file.Extension = "." + Filter Then AL_MediaFileAndPath.Add(file.FullName)
Console.WriteLine(file.FullName)

Try

Catch e As Exception
MsgBox("Problem to access File : " + file.FullName)

End Try
Next
Next Filter

For Each subDir In dir.GetDirectories
dir = subDir
BrowseForFiles()

Next
RaiseEvent ThreadComplete(AL_MediaFileAndPath)

Catch e As Exception
Main.cbo_NoAccesFileDirectory.Items.Add(dir.FullName) 'Add path to ComboBox.
Main.lbl_NoAccess.Visible = True 'Show Label.
Main.cbo_NoAccesFileDirectory.Visible = True 'Show ComboBox.

End Try

End Sub
end Class



Betreff Von Datum
Re: How to know that a thread has finshed.
Hi Theo,<br><br>yeah i know where you made a mistake. <br><br>Private WithEvents evBFMF As clsFilesAndFolders<br><br>You never use it in the code sample but the ThreadComplete event is only handled for this...
Christian Hehtke 15.04.2006 18:50
Re: How to know that a thread has finshed.
Oh sorry i forgot to post you a little example of how to implement such a scenario under use of delegates.<br><br>Here it is. It executes a "verylongrunningtask" and then pops up a messagebox.<br><br> ...
Christian Hehtke 15.04.2006 18:54
Re: How to know that a thread has finshed.
Daer Christian,<br><br>Thank you very much for your answer.<br>MY first problem solved. After I changed the HANDLER I got the message.<br><br>The solution is out of my intellectual range (newbie), that means I...
G. Guest 16.04.2006 20:40
Re: How to know that a thread has finshed.
Hi Theo,<br><br>i would prefer a class like this you have a progress and you have a complete event and you can cancel the operation.<br>i did not test the cancel method ;)<br><br>hope it works for you...
Christian Hehtke 16.04.2006 23:36
Re: How to know that a thread has finshed.
Dear Christian,<br>Thank your very much for your effort to help me.<br><br>I have made another Project to test your code. It seems, your code is working fine.<br><br>In course of the next week I'm going to try...
Theo Driemann 17.04.2006 00:54
Re: How to know that a thread has finshed.
Dear Christian,<br><br>It is hard for me to follow the code you wrote, but it still works and I think it is even faster than my one. I added some lines, to catch errors when the program tries to access...
Theo Driemann 17.04.2006 18:39
Re: How to know that a thread has finshed.
you just have to call the Stop() method of the FileSearcher instance.<br><br>mfg
G. Guest 18.04.2006 08:56
Re: How to know that a thread has...
Dear Christian,<br>Maybe you have time to answer the my last 2 question.<br><br>First, the stop method wasn't working, until I declared Dim fs As New clsSearchFiles.FileSearcher(_StartupDir, New...
G. Guest 20.04.2006 20:55
Re: How to know that a thread has finshed.
Dear Christian,<br>Maybe you have time to answer the my last 2 question.<br><br>First, the stop method wasn't working, until I declared Dim fs As New clsSearchFiles.FileSearcher(_StartupDir, New String()...
Theo Driemann 20.04.2006 21:28
Re: How to know that a thread has finshed.
i will take a look at the code this evening. <br><br>mfg
G. Guest 21.04.2006 09:16
Re: How to know that a thread has...
hi, <br><br>i think you should read a book about object orientation.<br><br>if fixed the code and dropped the class you build because i did not see any sense in it sorry. <br><br>this is a short example... i let...
Christian Hehtke 22.04.2006 12:07
Re: How to know that a thread has...
Dear Christian.<br><br>Thanks a lot. Know I can use your code complete.<br><br>Your are right I have to read a book. But you remember, at the beginning of our dialog I mentoined that I am a newbie. <br><br>I'm in...
Theo Driemann 22.04.2006 17:59

Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!

 Betreff:
 Nachricht: Den Beitrag finden Sie nun unter: http://beta.devtrain.de/foren Die Benutzerdaten und Foreninhalte von beta.devtrain.de und www.devtrain.de sind die selben.
Sie können sich dort sogar per RSS über neue Inhalte informieren lassen.
Bei Problemen bitte direkt Mail an asp [AT] ppedv.de.

 Signatur:

  



Login
Username:


Passwort:






Passwort vergessen?

Advanced Developers Conference vom 14.-15. Februar 2011

© Copyright 2003 ppedv AG