borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (VB file storage problem...help!!!) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Is there a method in VB to set timeout on a function
Poster Message
makinha
Level: Trainee

Registered: 02-08-2006
Posts: 2

icon Is there a method in VB to set timeout on a function

Hello,

In VB.NET is there a function to keep track a function runtime,  let say if I have a function called

func_may_hang(input_val) with return code integer

this function will return a positive return code when it completed, however if there is any error in between then it wait forever without any return code. Therefore, my following code will NOT work, as it keep waiting and no negative return code pass back.

       If func_may_hang(FilePath) Then
           statement 1
        else
           statement 2
        end if

So, I wonder if VB.NET have any function to monitor a function runtime, and available to set timeout for the function, so that if it cannot complete within the time limit, then force to pass a negative return code?  any idea?


like:

method.timeout = 5000 ' 5000 mil sec

If (method.run(func_may_hang(FilePath)) then
           statement 1
else
           statement 2
end if

Is it possible?? thanks.

26-10-2007 at 09:10 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 896
icon Re: Is there a method in VB to set timeout on a function

Hi,
There's no direct timeout on this type of thing - what you need are timers & threads.
The easiest way is to add a timer to your project.
Set a flag somewhere to say "this method has started"
start your timer
start your method
when your method finishes, clear the flag
when the timer "ticks", check the flag and act accordingly.

If you can't abort your "long" method, then you should start it in a seperate thread - See ThreadStart in VB.Net

Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

08-11-2007 at 07:02 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Is there a method in VB to set timeout on a function
Next Topic (VB file storage problem...help!!!) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder