1 pièce(s) jointe(s)
Problème association et stackoverflow
Bonsoir,
Je suis actuellement en train de créer une application en wpf permettant entre autre de récupérer des informations sur un fichier texte. J'ai cherché des réponses, mais j'ai eu des problèmes concernant l'association entre mes 2 classes CFichier(contenant donc la méthode pour récupérer les fichiers) et ma classe d'interface MainWindow. Je n'ai pas d'erreur de code mais j'ai un doute sur la réalisation de l'association... De plus j'ai un problème de stackoverflow lors de l'instanciation de mon objet interface:
Voici ma classe d'interface GestionEtiquette:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Imports System.IO
Imports System.IO.FileSystemWatcher
Imports System.Threading
Imports System.Windows.Controls
Imports System.Windows
Imports System.Collections
Imports System.Security.Permissions
Imports System.IO.FileSystemEventArgs
Imports Integration.CFichier
Class GestionEtiquette
Dim ObjetFichier As New CFichier
Dim chemin As String = "C:\temp"
Delegate Sub CallBackToUIThread(ByVal e As FileSystemEventArgs)
Public Sub GestionEtiquette()
InitializeComponent()
End Sub
Public Sub NotifyUIThreadOfChange(ByVal e As FileSystemEventArgs)
ObjetFichier.recuperationAffichage(chemin)
End Sub
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Try
Dim Path As String = "C:\temp\FichierProdX"
Dim watcher As New FileSystemWatcher()
watcher.Path = Path
' Watch for changes in LastAccess and LastWrite times, and
' the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.LastWrite
' Only watch text files.
watcher.Filter = "*.txt"
' Add event handlers.
AddHandler watcher.Changed, AddressOf OnChanged
' Begin watching.
watcher.EnableRaisingEvents = True
Catch ex As Exception
MsgBox("Erreur chargement")
End Try
End Sub
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
Me.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, New CallBackToUIThread(AddressOf NotifyUIThreadOfChange), e)
End Sub
End Class |
Et voici la classe CFichier:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
Public Class CFichier
Dim ptr As New GestionEtiquette
Public Sub CFichier()
Me.SetGestionEtiquette(ptr)
End Sub
'Relation association'
Public Sub SetGestionEtiquette(ByRef ObjetGestionEtiquette As GestionEtiquette)
ptr = ObjetGestionEtiquette
End Sub
'Paramètre d'entrée : chemin
'Paramètre de sortie :
'Paramètre E/S :
'Resultat :
'Description de la méthode : permet récupération des informations d'un fichier texte et l'affichage dans une interface
'Variable globale :
Public Sub RecuperationAffichage(chemin)
Try
Dim Reader As New IO.StreamReader(chemin.ToString())
'chemin du fichier'
Dim Debut, Fin, i As Integer
Debut = 1
Fin = 12
i = 0
While i <= Fin
If i < Debut Then
'On lit dans le vide
MsgBox("rien a lire")
Else
'On assigne bien les lignes voulues
Dim ligne As String = Reader.ReadLine
Dim result As Object = ptr.GroupBox5.FindName("TextBox" & i)
If TypeOf result Is TextBox Then
Dim wantedChild As TextBox = TryCast(result, TextBox)
wantedChild.Text = ligne
End If
End If
i += 1
End While
Reader.Close()
Catch ex As IOException 'en cas d'erreurs
MsgBox("erreur bouton")
End Try
End Sub
End Class |
et mon code d'erreur en pièce jointe.