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

VB.NET Discussion :

Mon programme consomme beaucoup d'UC [Débutant]


Sujet :

VB.NET

  1. #1
    Membre du Club
    Homme Profil pro
    Apprenti développeur
    Inscrit en
    Février 2014
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France

    Informations professionnelles :
    Activité : Apprenti développeur

    Informations forums :
    Inscription : Février 2014
    Messages : 102
    Points : 58
    Points
    58
    Par défaut Mon programme consomme beaucoup d'UC
    Bonjour,

    Voila j'ai un probleme, j'ai un progrmme qui check la présence d'une base puis d'un lecteur en permanance. Pour cela j'utilise dans un Thread des While True, afin de Check constamment, si un lecteur est posé sur la base..

    Mon programme est un service qui utilise un canal nommé.

    Pourquoi mon programme consomme-t-il tant de ressources?

    Voici mon programme :


    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
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    Imports System.Threading
    Imports System.Text
    Imports System.IO
    Imports Ionic.Zip
    Imports System.Configuration.Install
    Imports System.Windows.Forms
     
    Public Class ERTool
     
     
        Public MonThreadPresenceBase As New Thread(AddressOf FonctionThreadPresenceBase)
        Public MonThreadPipeConnect As New Thread(AddressOf FonctionThreadPipeConnect)
        Public MonThreadPipeConnect2 As New Thread(AddressOf FonctionThreadPipeConnect2)
        Public MonThreadAffiche As New Thread(AddressOf FonctionThreadAffiche)
     
        'Public MonThread As New Thread(AddressOf FonctionThread)
     
        Public Declare Function Term_CommCall Lib "Bp02SCK.dll" (ByRef TermNo As Integer, ByRef SerialNo As Int16) As Int16
        Public Declare Function TermUpLoadMapEx Lib "Bp02SCK.dll" (ByRef tMapNo As Integer, ByRef tMapLen As Byte, ByRef tSize As Byte, ByRef tBeginRecordNo As Integer, ByRef tEndRecordNo As Integer, ByRef tBaseRecordNo As Integer, ByRef tNoUpLoadNum As Integer, ByRef pCardMapTemp As Byte) As Int16
        Public Declare Function TermRecord Lib "Bp02SCK.dll" (ByVal Control As Byte, ByRef pData As Byte, ByRef NoUpLoadNum As Int16, ByRef RecordBaseOver As Boolean, ByRef CardMapOver As Boolean) As Int16
        Public Declare Function Term_SysInit Lib "Bp02SCK.dll" () As Int16
        Public Declare Function Term_ReadTime Lib "Bp02SCK.dll" (ByRef FDate As Date, ByRef FTime As Date) As Int16
        Public Declare Function Term_SetTime Lib "Bp02SCK.dll" (ByVal FDate As Date, ByVal FTime As Date) As Int16
        Public Declare Function TermRecordBase Lib "Bp02SCK.dll" (ByRef BaseRecordNo As Integer, ByRef NoUpLoadNum As Int16) As Int16
        Public Declare Function Term_CommOpen Lib "Bp02SCK.dll" (ByVal PortName As String) As Int16
        Public Declare Function Term_CommClose Lib "Bp02SCK.dll" () As Int16
        Public Declare Function StationCall Lib "Bp02SCK.dll" (ByRef SerialNo As Int16, ByRef StationID As Integer) As Integer
     
        Dim f As New FichierConfig
     
        Dim clientPipe As New System.IO.Pipes.NamedPipeClientStream("PIPE")
        Dim serverPipe As New System.IO.Pipes.NamedPipeServerStream("MSGBOX", Pipes.PipeDirection.Out)
     
     
     
        Protected Overrides Sub OnStart(ByVal args() As String)
            'Ajoutez ici le code pour démarrer votre service. Cette méthode doit
            'démarrer votre service.
     
            'If Not IsProcessRunning("ERToolMsg") Then
            '    Process.Start("C:\Users\KRO\Desktop\projet6\ERToolMsg2\ERToolMsg\bin\Debug\ERToolMsg.exe")
            'End If
     
            If Not System.IO.Directory.Exists("C:\ERConfig") Then
                System.IO.Directory.CreateDirectory("C:\ERConfig")
            End If
     
     
            If Not System.IO.File.Exists("C:\ERConfig\ERTool.ini") Then
                f.EcritureConfig(Application.StartupPath & "\CSV\", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Guardeo Vision\ExternalFiles\")
            End If
     
     
            MonThreadPresenceBase.Start()
            MonThreadPipeConnect.Start()
            MonThreadPipeConnect2.Start()
     
        End Sub
     
        Protected Overrides Sub OnStop()
            ' Ajoutez ici le code pour effectuer les destructions nécessaires à l'arrêt de votre service.
     
     
            clientPipe.Close()
            serverPipe.Disconnect()
     
            MonThreadPresenceBase.Abort()
            MonThreadPipeConnect.Abort()
            MonThreadPipeConnect2.Abort()
     
     
        End Sub
     
     
     
        Dim VariableLock1 As Object = New Object()
        Public Sub FonctionThreadPipeConnect()
            SyncLock VariableLock1
                While True
     
                    While Not clientPipe.IsConnected
                        clientPipe.Connect()
                    End While
                End While
            End SyncLock
        End Sub
     
     
        Dim VariableLock2 As Object = New Object()
        Public Sub FonctionThreadPipeConnect2()
            SyncLock VariableLock2
                While True
     
                    While Not serverPipe.IsConnected
                        serverPipe.WaitForConnection()
                    End While
                End While
            End SyncLock
        End Sub
     
     
     
     
        Dim VariableLock3 As Object = New Object()
        Public Sub FonctionThreadPresenceBase()
            SyncLock VariableLock3
     
                Dim Temp As Integer
                Dim StationNo As Integer
                Dim SerialNo As Int16
     
                While True
                    While True
     
                        '-------------VERIFICATION PRESENCE BASE--------------------------
     
                        'Si la connexion avec ERTag n'est pas effectuée, alors : 
                        If clientPipe.IsConnected Then
     
                            Term_CommClose()
                            ' While clientPipe.IsConnected 'ERREUR ICI, clientPipe reste connecté...
                            Do
     
     
                                Dim B(0 To 1000) As Byte
                                Dim L As Integer = clientPipe.Read(B, 0, B.Length)
     
                            Loop While clientPipe.IsConnected
     
                        Else
     
     
                            Temp = StationCall(SerialNo, StationNo)
                            If Temp = 1 Then   'Si l'appel de la station est effectué
     
                                'NotifyIcon1.Icon = New Icon("ERTool.ico")
                                'Verifier presence Lecteur
                                FonctionPresenceReader()
                                Thread.Sleep(1000)
     
                            Else
                                'NotifyIcon1.Icon = New Icon("ERTool-stop.ico")
                                Term_CommClose()
                                scanPort()
     
                            End If
                        End If
     
                    End While
                End While
            End SyncLock
     
        End Sub
     
     
     
     
        Sub FonctionPresenceReader()
     
            'Chemin du fichier
            Dim i, j As Int16
     
            Dim FailCount As Int16
            Dim bTemp, bTemp1 As Int16
            Const COMM_DATA_LEN As Int16 = 6
            Dim tMapNo As Integer
            Dim tMapLen As Byte
            Dim tSize As Byte
            Dim tBeginRecordNo As Integer
            Dim tEndRecordNo As Integer
            Dim tBaseRecordNo As Integer
            Dim tNoUpLoadNum As Integer
            Dim TemNo As Integer
            Dim SerialNo As Int16
            'FonctionLect
            Dim Texta As String
            Dim Textb = New StringBuilder
            Dim Textc As String
            Dim iTemp As Int16
            Dim PackNum As Int16
            Dim Control As Byte
            Dim RecordNo As Integer
            Dim RecordNum As Int16
            Dim CardID(5) As Byte
            Dim CardName As String
            Dim Fyear, Fmonth, Fday, Fhour, Fminute, Fsecond As Int16
            Dim pCardMapTemp(6000) As Byte
            Dim NoUpLoadNum As Int16
            Dim RecordBaseOver, CardMapOver As Boolean
            Dim RecordType As Byte
            Dim TempBuf(1000) As Byte
            Dim fxml As New FichierConfig
            Dim y As Integer = 0
            Dim fichierXML As String = "Patrol_" & y.ToString("D4") & ".xml"
            Dim fichier As String = "Patrol_" & y.ToString("D4")
            Dim f As New FichierConfig
            Dim cheminXML As String = f.LectureConfigDirectory("cheminXML")
            'FILE'
            Dim objWriter
            '-----'
     
            Dim A() As Byte = System.Text.Encoding.GetEncoding("windows-1256").GetBytes("Téléchargement terminé, fichier XML disponible")
            Dim B() As Byte = System.Text.Encoding.GetEncoding("windows-1256").GetBytes("Aucune donnée à télécharger, veuillez retirer le lecteur")
     
     
     
     
            Texta = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & " " & "?>" & Chr(13) & Chr(10) _
                               & "<vision_request xmlns=" & Chr(34) & "http://www.capgemini.fr/services/vision" & Chr(34) & Chr(13) & Chr(10) _
                               & "xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & Chr(13) & Chr(10) _
                               & "xsi:schemaLocation=" & Chr(34) & "http://www.capgemini.fr/services/vision schThePipe.xsd" & Chr(34) & ">" & Chr(13) & Chr(10) _
                               & Chr(9) & "<round_insert>true</round_insert>" & Chr(13) & Chr(10) _
                               & Chr(9) & "<round_system>RS-The pipe</round_system>" & Chr(13) & Chr(10) _
                               & Chr(9) & "<duty>" & Chr(13) & Chr(10) _
                               & Chr(9) & Chr(9) & "<round>" & Chr(13) & Chr(10) _
                               & Chr(9) & Chr(9) & Chr(9) & "<list_tag>" & Chr(13) & Chr(10)
     
     
            Textc = Chr(9) & Chr(9) & Chr(9) & "</list_tag>" & Chr(13) & Chr(10) _
                                & Chr(9) & Chr(9) & "</round>" & Chr(13) & Chr(10) _
                                & Chr(9) & "</duty> " & Chr(13) & Chr(10) _
                                & "</vision_request>"
     
     
     
     
            While True
     
     
     
     
                '-------------VERIFICATION PRESENCE LECTEUR--------------------------'
     
                'Si il n'y a pas de lecteur
                If Term_CommCall(TemNo, SerialNo) = -1 Then
     
     
                    Exit While
     
                Else
     
     
                    'Lecture enregistrements
                    iTemp = TermUpLoadMapEx(tMapNo, tMapLen, tSize, tBeginRecordNo, tEndRecordNo, tBaseRecordNo, tNoUpLoadNum, pCardMapTemp(0))
                    If iTemp = -1 Then
                        'Error1
                        Exit While
                    End If
     
     
                    If iTemp = -2 Then
                        'Error2
     
                        Exit While
                    End If
     
     
                    Control = 0
                    RecordNum = 0
                    FailCount = 0
     
    gWhile:
     
                    While True
     
                        PackNum = TermRecord(Control, TempBuf(0), NoUpLoadNum, RecordBaseOver, CardMapOver)
     
                        Control = 0  'not to move record pointer
                        If PackNum < 0 Then
     
                            FailCount = FailCount + 1
                            If FailCount > 5 Then
     
                                Exit While
                            End If
                            GoTo gWhile
                        End If
     
     
     
                        'Pas d'enregistrements à Télécharger
                        If PackNum = 0 Then
                            If NoUpLoadNum = 0 Then
                                y = 0
                                If Not Directory.Exists(cheminXML) Then
                                    Directory.CreateDirectory(cheminXML)
                                End If
     
                                While System.IO.File.Exists(cheminXML & fichier & ".zip")
                                    y = y + 1
                                    fichier = "Patrol_" & y.ToString("D4")
                                    fichierXML = "Patrol_" & y.ToString("D4") & ".xml"
                                End While
     
                                'Création du fichier
                                System.IO.File.Create(cheminXML & fichierXML).Dispose()
     
                                'Si il n'y a pas de tag enregistré dans le lecteur
                                If IsNothing(Textb) Or Textb.Length = 0 Then
                                    'On supprime le fichier
                                    System.IO.File.Delete(cheminXML & fichierXML)
     
                                Else
                                    'Sinon si le Textb n'est pas vide
                                    'On créé une instance objWriter
                                    objWriter = New System.IO.StreamWriter(cheminXML & fichierXML, True)
     
                                    objWriter.WriteLine(Texta)
                                    objWriter.WriteLine(Textb)
                                    objWriter.WriteLine(Textc)
                                    objWriter.Close()
     
                                    CompressFile(cheminXML & fichierXML)
     
                                    'System.IO.File.Delete(cheminXML & fichierXML)
                                    'ON A SUPPRIME LE FICHIER, il faut donc le recreer.
                                    System.IO.File.Delete(cheminXML & fichierXML)
     
                                    Textb.Length = 0
                                    y = y + 1
     
                                    fichierXML = "Patrol_" & y.ToString("D4") & ".xml"
                                    UpdateClock()
                                    'MsgBox("Téléchargement terminé, fichier XML disponible", 4096 + 64, "ERTool")
                                    'MessageBox.Show("Téléchargement terminé, fichier XML disponible", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
     
                                    If serverPipe.IsConnected Then
                                        Try
                                            serverPipe.Write(A, 0, A.Length)
                                            serverPipe.WaitForPipeDrain()
                                        Catch ex As IOException
                                        End Try
     
                                    End If
     
                                End If
     
     
                                'MsgBox("Aucune donnée à télécharger, veuillez retirer le lecteur", 4096 + 48, "ERTool")
                                'MessageBox.Show("Aucune donnée à télécharger, veuillez retirer le lecteur", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
     
                                If serverPipe.IsConnected Then
                                    Try
                                        serverPipe.Write(B, 0, B.Length)
                                        serverPipe.WaitForPipeDrain()
                                    Catch ex As IOException
                                    End Try
                                End If
     
                                Exit Sub
     
                            End If
     
                            If RecordBaseOver Then
                                If TermRecordBase(tBaseRecordNo, NoUpLoadNum) = False Then
                                    If TermRecordBase(tBaseRecordNo, NoUpLoadNum) = False Then
     
                                        Exit While
                                    End If
                                End If
     
     
                                GoTo gWhile
                            End If
     
                            If CardMapOver Then
     
                                If iTemp = -1 Then
                                    ' Text1.Text = "Error!"
                                    Exit While
                                End If
     
                                If iTemp = -2 Then
                                    ' Text1.Text = "Error!"
                                    Exit While
                                End If
                            End If
                            GoTo gWhile
                        End If
     
                        For i = 0 To (PackNum - 1)
     
                            RecordNo = TempBuf(i * COMM_DATA_LEN) + tBaseRecordNo
                            RecordType = TempBuf(i * COMM_DATA_LEN + 1)
     
                            'Fsecond
                            bTemp = TempBuf(i * COMM_DATA_LEN + 2)
                            For j = 0 To 1
                                bTemp = Fix(bTemp / 2)
                            Next j
                            bTemp = bTemp And 63
     
                            Fsecond = bTemp
     
                            'Fminute
                            bTemp = TempBuf(i * COMM_DATA_LEN + 2)
                            bTemp1 = TempBuf(i * COMM_DATA_LEN + 3)
     
     
                            For j = 0 To 3
                                '-----------------------------
                                bTemp = bTemp * 2
                            Next j
                            bTemp = bTemp And 48
     
                            For j = 0 To 3
                                bTemp1 = Fix(bTemp1 / 2)
                            Next j
                            bTemp1 = bTemp1 And 15
                            '-----------------------------
     
                            Fminute = bTemp Or bTemp1
     
     
                            'Fhour
                            bTemp = TempBuf(i * COMM_DATA_LEN + 3)
                            bTemp1 = TempBuf(i * COMM_DATA_LEN + 4)
     
     
                            For j = 0 To 6
                                bTemp1 = Fix(bTemp1 / 2)
                            Next j
                            bTemp1 = bTemp1 And 1
                            '---------------------------------
                            bTemp = (bTemp * 2) And 30
                            '---------------------------------
                            Fhour = bTemp Or bTemp1
     
     
     
     
                            'Fday
                            bTemp = TempBuf(i * COMM_DATA_LEN + 4)
                            For j = 0 To 1
                                bTemp = Fix(bTemp / 2)
                            Next j
                            bTemp = bTemp And 31
                            Fday = bTemp
     
     
                            'Fmonth
                            bTemp = TempBuf(i * COMM_DATA_LEN + 4)
                            bTemp1 = TempBuf(i * COMM_DATA_LEN + 5)
     
                            bTemp = (bTemp * 2 * 2) And 12
                            For j = 0 To 5
                                bTemp1 = Fix(bTemp1 / 2)
                            Next j
                            bTemp1 = bTemp1 And 3
                            Fmonth = bTemp Or bTemp1
     
     
     
                            'Fyear
                            bTemp = TempBuf(i * COMM_DATA_LEN + 5)
                            Fyear = ((bTemp And 63) + 2000)  '(bTemp And 63)
     
     
     
                            For j = 0 To 5
                                CardID(j) = pCardMapTemp(RecordType * 6 + j)
                            Next
     
                            CardName = ""
     
                            For j = 1 To 5
                                '-------------------------------------please change i to j
                                If Len(Hex(CardID(j))) = 1 Then
                                    CardName = CardName + "0" + Hex(CardID(j))
                                Else
                                    CardName = CardName + Hex(CardID(j))
                                End If
                                '------------------------------------
                            Next j
     
                            'Save Data to DataSet
                            If RecordType < 200 Then
                                RecordType = 0
                            End If
     
                            RecordNum = RecordNum + 1
     
     
     
                            Textb.Append(Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<tag>" & Chr(13) & Chr(10) _
                                   & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<id>" & CardName & "</id>" & Chr(13) & Chr(10) _
                                   & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<timestamp>" & Fyear.ToString("D2") & "-" & Fmonth.ToString("D2") & "-" & Fday.ToString("D2") & "T" & Fhour.ToString("D2") & ":" & Fminute.ToString("D2") & ":" & Fsecond.ToString("D2") & "</timestamp>" & Chr(13) & Chr(10) _
                            & Chr(9) & Chr(9) & Chr(9) & Chr(9) & "</tag>" & Chr(13) & Chr(10))
     
                        Next i
     
                        Control = 1 ' to move record pointer
     
                    End While
     
                End If
            End While
     
     
     
        End Sub
     
     
     
        Private Sub CompressFile(ByVal path As String)
            Dim zipname = path.Split(".")(0)
            Try
                Using zip As ZipFile = New ZipFile
                    zip.AddFile(path, "")
                    zip.Save(zipname + ".zip")
                End Using
            Catch ex1 As Exception
                Console.Error.WriteLine("exception: {0}", ex1.ToString)
                'MsgBox("Erreur de compression du fichier xml", 4096 + 64, "ERTool")
            End Try
     
        End Sub
     
        Private Sub UpdateClock()
     
     
     
            Dim B() As Byte = System.Text.Encoding.GetEncoding("windows-1256").GetBytes("Synchronisation de la date et de l'heure effectuée")
     
            Dim FDate As Date
            Dim FTime As Date
            Dim FRDate As Date
            Dim FRTime As Date
            Dim rTemp As Int16
     
     
            'ON APPELLE LA DATE / HEURE DU PC
     
            FDate = DateValue(Now)
            FTime = TimeValue(Now)
     
            'ON APPELLE LA DATE / HEURE DU LECTEUR
     
            rTemp = Term_ReadTime(FRDate, FRTime)
            If rTemp = 0 Then
                'MsgBox("Impossible de lire la date/heure du lecteur", 4096 + 16, "ERTool")
                'MessageBox.Show("Synchronisation de la date et de l'heure effectuée", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
     
     
            End If
     
     
            Dim WindowsSeconds As Double = TimeSpan.Parse(FTime).TotalSeconds
            Dim Readerseconds As Double = TimeSpan.Parse(FRTime).TotalSeconds
     
     
            If FRDate <> FDate Then
                'MsgBox("Synchronisation de la date et de l'heure effectuée", 4096 + 64, "ERTool")
                'MessageBox.Show("Synchronisation de la date et de l'heure effectuée", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
                If serverPipe.IsConnected Then
                    Try
                        serverPipe.Write(B, 0, B.Length)
                        serverPipe.WaitForPipeDrain()
                    Catch ex As IOException
                    End Try
                End If
                Term_SetTime(FDate, FTime)
                Term_SysInit()
                Exit Sub
     
            ElseIf (WindowsSeconds - Readerseconds >= 60) Then
                ' MsgBox("Synchronisation de la date et de l'heure effectuée", 4096 + 64, "ERTool")
                'MessageBox.Show("Synchronisation de la date et de l'heure effectuée", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
                If serverPipe.IsConnected Then
                    Try
                        serverPipe.Write(B, 0, B.Length)
                        serverPipe.WaitForPipeDrain()
                    Catch ex As IOException
                    End Try
     
                End If
     
     
                Term_SetTime(FDate, FTime)
                Term_SysInit()
                Exit Sub
     
            ElseIf (WindowsSeconds - Readerseconds <= -60) Then
     
     
                'MsgBox("Synchronisation de la date et de l'heure effectuée", 4096 + 64, "ERTool")
                'MessageBox.Show("Synchronisation de la date et de l'heure effectuée", "ERTool", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
                If serverPipe.IsConnected Then
                    Try
                        serverPipe.Write(B, 0, B.Length)
                        serverPipe.WaitForPipeDrain()
                    Catch ex As IOException
                    End Try
     
                End If
     
     
                Term_SetTime(FDate, FTime)
                Term_SysInit()
                Exit Sub
     
            End If
        End Sub
     
     
     
        Sub scanPort()
            Dim k As Integer
            Dim A() As Byte = System.Text.Encoding.GetEncoding("windows-1256").GetBytes("ERTool en marche")
     
            For k = 1 To 50
                If Term_CommOpen("COM" & k.ToString) = 1 Then   'Si COMi ouvert
     
                    If serverPipe.IsConnected Then
                        Try
                            serverPipe.Write(A, 0, A.Length)
                            serverPipe.WaitForPipeDrain()
                        Catch ex As IOException
                        End Try
                    End If
     
     
                    Exit For
                End If
            Next k
     
        End Sub
     
     
        Dim VariableLock4 As Object = New Object()
        Public Sub FonctionThreadAffiche()
            SyncLock VariableLock4
                'Process.Start("C:\Users\KRO\Desktop\projet4\ERToolMsg2\ERToolMsg\bin\Debug\ERToolMsg.exe")
            End SyncLock
        End Sub
     
     
     
        Private Function IsProcessRunning(ByVal processName As String) As Boolean
     
            Dim p() As Process
            p = Process.GetProcessesByName(processName)
            If p.Count > 0 Then
                Return True
            Else
                Return False
            End If
        End Function
     
     
    End Class

  2. #2
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Tu peux essayer de voir avec un profiler ou il passe son temps.
    Ou alors en debug. C'est pas un truc genre Socket.read qui bloque tout?
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  3. #3
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    un while true consomme en théorie 100% de processeur

    et ca ne sert en général à rien de tester un truc qu'on attend toutes les nanosecondes

    aussi toujours mettre un thread.sleep dans un while true

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    while true
       ' test condition de sortie
       system.threading.thread.sleep(5)
    end while
    déjà avec 1 milliseconde ca devrait relacher pas mal de cpu
    et au moins 10 si vous voulez en lacher plus
    à adapter à ce que vous faites, plus vous attendrez moins vous consommerez (de manière logarithmique et non proportionnelle)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  4. #4
    Membre du Club
    Homme Profil pro
    Apprenti développeur
    Inscrit en
    Février 2014
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France

    Informations professionnelles :
    Activité : Apprenti développeur

    Informations forums :
    Inscription : Février 2014
    Messages : 102
    Points : 58
    Points
    58
    Par défaut
    Merci Popol

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

Discussions similaires

  1. Programme qui consomme beaucoup de CPU
    Par houssine91 dans le forum Général Java
    Réponses: 4
    Dernier message: 16/03/2013, 15h18
  2. Comment récupérer la consommation mémoire de mon programme
    Par youpileouf dans le forum Threads & Processus
    Réponses: 6
    Dernier message: 11/09/2010, 18h15
  3. programme qui consomme beaucoup de memoire
    Par gaut dans le forum Windows
    Réponses: 10
    Dernier message: 01/02/2005, 20h33
  4. [] Utiliser AVI d'une DLL dans mon programme
    Par seb.49 dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 02/05/2003, 14h52
  5. Réponses: 11
    Dernier message: 17/03/2003, 10h56

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