Click here to Skip to main content
15,881,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim check As Thread
    Private Sub RunThread()
        Dim newThread1 As New ThreadStart(AddressOf Checkdata)
        check = New Thread(newThread1)
        check.Start()
    End Sub
    Private Sub Checkdata()
        Dim dt As Date
        Dim dset As DataSet
        Dim prr() As Object
        dt = Date.Now.AddMinutes(5)
        For i As Integer = 0 To 5
            If Date.Now > dt Then
                dt = Date.Now.AddMinutes(1)
                prr = {objBranch.BranchKey}
                Try
                    Dim objUIDataGetBranch As BranchSelectionFetch.UIDataWCFClient
                    objUIDataGetBranch = New BranchSelectionFetch.UIDataWCFClient("IndependentFetchDataEndPtHttp")
                    byteBranchSelectionData = objUIDataGetBranch.WCFAuxValuesByte(CRisMACEntity.ApplicationDown, prr)
                    objUIDataGetBranch.Close()
                    prr = Nothing
                    DecompressData(byteBranchSelectionData)
                    dset = ds
                Catch ex As Exception

                End Try

                If dset IsNot Nothing Then
                    If dset.Tables(0).Rows.Count > 0 Then                        
                                Application.ExitThread()
                                Application.Exit()
                                Application.DoEvents()
                                check.Abort()                       
                    End If
                End If
            End If
            i = 0
        Next
    End Sub


Here is Code how Can i reduce cpu utilization Any One Help
Thanks
Posted
Updated 26-Mar-14 3:19am
v3

1 solution

Put a Thread.Sleep(15000) just before your Next statement.

This will force the thread to go to sleep for 15 seconds freeing up the CPU to do other things.

Ummm...What's with the Application.ExitThread(), Application.Exit() and Application.DoEvents() calls? You don't need any of them. Get rid of them.
 
Share this answer
 
Comments
Naim_86 26-Mar-14 10:54am    
thanks for reply
application.exit use to stop working
and is thread.abort clear running thread.
Dave Kreskowiak 26-Mar-14 10:59am    
Wrong way to do it.

In your case there, all you need is Exit Sub and the thread will die with it.
pdoxtader 26-Mar-14 14:30pm    
Dave's right. Exit Sub, or a simple Return will get you out of that Sub. Calling Application.Exit() from a background thread is ugly at best. In general, you want to let the user decide when he / she wants to close the application - not have it suddenly disappear.
Naim_86 2-Apr-14 1:47am    
Thanks For Responce
But I Question is for when a server is not Available for any type of Operation Then i want to Exit Application forcefully thats why i m using thread to check server Availibility in background , so please sugges me any other solution

Thanks
Dave Kreskowiak 2-Apr-14 8:28am    
You don't need to check for "server availability" at all! Just run the query and wrap it in a Try/Catch block. If the query fails, you've got your answer. You can do whatever you need to in the Catch block and Exit from there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900