IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Blocage du BackgroundWorker en [VB.NET]


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 32
    Par défaut Blocage du BackgroundWorker en [VB.NET]
    Bonjour,

    Dans mon application VB.net, j'utilise un BackgroundWorker pour faire du stokage de datas dans un serveur SQL. Pour savoir si la BackgroundWorker est occupé j'utilise IsBusy, mais il arrive que cette propriété ne passe pas à FALSE si j'appele le BackgroundWorker trop souvent. J'ai limité la fonction dans le BackgroundWorker au strict minimum (ecriture d'une ligne dans le debuger) et j'ai le meme probleme
    quelqu'un serait il m'aider ?
    @+ et merci d'avance.

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    c'est pas très clair ton histoire... on peut voir un bout de code ?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 32
    Par défaut
    Voici mon code qui appel le backgroundworker. C'est ce coder ci dessous qui peut etre appelé plusieurs fois par seconde.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    'Démarrage de la tache d'enregistrement des datas dans la base SQL
                    If ChkSaveDbSqlServer.Checked And BgWSQL.IsBusy = False Then
                        BgWSQL.RunWorkerAsync(SQLAlmDiag)
                    Else
                        If ChkSaveDbSqlServer.Checked And BgWSQL.IsBusy = True Then
                            'Envoi des valeurs dans le tampon
                            Debug.Print("SQl Busy")
                        End If
                    End If
    et voici le code du backgroundworker

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    67
    68
    69
    70
     
    Private Sub BgWSQL_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BgWSQL.DoWork
            Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
            e.Result = SQLStore(SQLAlmDiag, worker, e)
        End Sub
     
        Public Function SQLStore(ByVal AlmDiag As DiagBufferData, ByVal worker As BackgroundWorker, ByVal e As DoWorkEventArgs) As Integer
            Dim strConnexion As String = "Data Source=LOGIN; Integrated Security=SSPI;" + "Initial Catalog=maBaseDeTest"
            Dim strRequete As String = "SELECT * FROM AlmDiag"
            Dim oConnection As New SqlConnection(strConnexion)
            Dim Result As Integer = Nothing
            Try
                If worker.CancellationPending Then
                    e.Cancel = True
                Else
                    'Connexion sur la database
     
                    oConnection.Open()
                    Debug.Print("Ouverture de la connexion")
                    ' Chargement de la liste des catégories dans oDataSet
                    Dim oSqlDataAdapter As New SqlDataAdapter(strRequete, oConnection)
     
                    Dim oDataSet As New DataSet("AlmDiag")
                    oSqlDataAdapter.Fill(oDataSet, "AlmDiag")
                    Debug.Print("Remplissage du Dataset")
                    oSqlDataAdapter.InsertCommand = New SqlCommand("INSERT INTO AlmDiag(Date,AcqErrMessage,DateApparition,DateDisparition,DiagItentifiant,EmplacementDfb,EtatAlarme,ImgDiag,NomInstanceDfb,TypeAlarmMessage,TypeDfb,Zone) Values(@Date,@AcqErrMessage,@DateApparition,@DateDisparition,@DiagItentifiant,@EmplacementDfb,@EtatAlarme,@ImgDiag,@NomInstanceDfb,@TypeAlarmMessage,@TypeDfb,@Zone)", oConnection)
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@Date", SqlDbType.DateTime, 20, "Date")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@AcqErrMessage", SqlDbType.NVarChar, 200, "AcqErrMessage")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@DateApparition", SqlDbType.DateTime, 20, "DateApparition")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@DateDisparition", SqlDbType.DateTime, 20, "DateDisparition")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@DiagItentifiant", SqlDbType.NVarChar, 10, "DiagItentifiant")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@EmplacementDfb", SqlDbType.NVarChar, 200, "EmplacementDfb")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@EtatAlarme", SqlDbType.NVarChar, 200, "EtatAlarme")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@ImgDiag", SqlDbType.NVarChar, 10, "ImgDiag")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@NomInstanceDfb", SqlDbType.NVarChar, 10, "NomInstanceDfb")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@TypeAlarmMessage", SqlDbType.NVarChar, 10, "TypeAlarmMessage")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@TypeDfb", SqlDbType.NVarChar, 10, "TypeDfb")
                    oSqlDataAdapter.InsertCommand.Parameters.Add("@Zone", SqlDbType.Int, 8, "Zone")
     
                    Dim oDataRow As DataRow
                    oDataRow = oDataSet.Tables("AlmDiag").NewRow()
                    oDataRow("Date") = FormatDateTime(Now, DateFormat.ShortDate) & " " & FormatDateTime(Now, DateFormat.LongTime)
                    oDataRow("AcqErrMessage") = AlmDiag.AcqErrMessage
                    oDataRow("DateApparition") = AlmDiag.DateApparition
                    If AlmDiag.DateDisparition <> "" Then oDataRow("DateDisparition") = AlmDiag.DateDisparition
                    oDataRow("DiagItentifiant") = AlmDiag.DiagItentifiant
                    oDataRow("EmplacementDfb") = AlmDiag.EmplacementDfb
                    oDataRow("EtatAlarme") = AlmDiag.EtatAlarme
                    oDataRow("ImgDiag") = AlmDiag.ImgDiag
                    oDataRow("NomInstanceDfb") = AlmDiag.NomInstanceDfb
                    oDataRow("TypeAlarmMessage") = AlmDiag.TypeAlarmMessage
                    oDataRow("TypeDfb") = AlmDiag.TypeDfb
                    oDataRow("Zone") = AlmDiag.Zone
                    oDataSet.Tables("AlmDiag").Rows.Add(oDataRow)
                    Debug.Print("Ajout du nouvelle enregistrement")
                    'Mise à jour de la source de données à partir du DataSet
                    Result = oSqlDataAdapter.Update(oDataSet, "AlmDiag")
                    Debug.Print("Mise a jour de la base SQL")
                End If
            Catch ex As Exception
                'Gestion des erreurs
                Debug.Print(ex.Message)
            Finally
                'Fermeture de la connexion
                oConnection.Close()
                Debug.Print("Fermeture de la Database")
            End Try
            Debug.Print("Fin du background")
            Return Result
        End Function
    en esperant que cela puisse t'aider
    @+

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    ben là y a rien qui me choque...
    ça veut dire quoi, "IsBusy ne passe pas à False" ? tu veux dire, jamais ? c'est pas un bloquage au niveau de SQL Server (verrou par exemple) ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Juin 2004
    Messages
    32
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2004
    Messages : 32
    Par défaut
    Bah le Isbusy = true si mon BackGroundworker est en cours d'utilisation donc ce qui peut arriver si la fonction est appelée plus rapidement que son temps d'execution. Le probleme c'est que j'ai l'impression que si je l'appel alors qu'elle en cours d'execution la tache se bloque et reste bloquée meme si elle n'est pas appelée...
    @+

  6. #6
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Tu ne peux pas relancer le backgroundworker quand il est en cours d'exécution, ça lèverait une InvalidOperationException...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VB.NET] Fenêtre modale sans blocage de code, c'est possible ?
    Par loki9481 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 24/05/2007, 14h17
  2. [.NET 2.0] Probleme de BackgroundWorker
    Par Aspic dans le forum Windows Forms
    Réponses: 5
    Dernier message: 22/03/2007, 15h13
  3. [VB.net] backgroundworker et UC à 100%
    Par grand_prophete dans le forum Windows Forms
    Réponses: 3
    Dernier message: 15/05/2006, 15h39
  4. [FW2.0][VB.net] backgroundworker
    Par grand_prophete dans le forum Windows Forms
    Réponses: 5
    Dernier message: 03/05/2006, 15h02
  5. Blocage dans la configuration oracle net
    Par nazimb dans le forum Oracle
    Réponses: 4
    Dernier message: 09/04/2006, 15h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo