Results 1 to 4 of 4

Thread: [RESOLVED] Create processing time limit

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Resolved [RESOLVED] Create processing time limit

    I have a process that recieves a request and issues a response. Sometimes createing the response is taking too long. I would like to start the request, and after 8 seconds, if the response has been created, I would abort the process and send back a generic message. All suggestions and ideas are welcome.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Create processing time limit

    You could capture the time before you start creating the response using Date.Now and during the creation of the response keep subtracting the initial Date you recorded from Date.Now. You would receive a TimeSpan object from which you can get how by how many seconds they differ.

    Here is an example:-
    vbnet Code:
    1. '
    2.         Dim T As Date = Date.Now
    3.  
    4.         'Imagine this is your long running process
    5.         Do
    6.  
    7.             'End the process after 8 seconds
    8.             If (Date.Now - T).TotalSeconds >= 8 Then Exit Do
    9.  
    10.         Loop
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Create processing time limit

    you can use threading like so:

    Code:
            Dim MyThread As New Threading.Thread(AddressOf ProcessSub)
            Try
                MyThread.Start()
                If MyThread.Join(8000) Then
                    Return True 'Complete or whatever
                End If
                MyThread.Abort()
            Catch ex As Exception
            End Try
            Return False

  4. #4

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Create processing time limit

    That appears to be exactly what I'm looking for, thanks Grimfort.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width