473,411 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Need help on time out loop after certain time.

hello everyone.

Im trying to time out a loot after a certain time. Probably 5 to 10
minutes.

I have the following function

Private Sub processFileCreation(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim strFilename As String = "c:\web\example.mdb"
Do
Loop While System.IO.File.Exists(strFilename) And
isFileOpen(strFilename)
writeDatabase()

End Sub

This function is being called when it fires the event "created" of a
filewatcher. The file "example.mdb" is being FTPed to the folder. The
loop is to verify if the file is completed written on disk to avoid
exceptions. Is a big file that could take 5 minutes to FTP it that
why I need this loop. Im trying to avoid an infinite loop if some user
has the file open, or if the file is being used by any other software,
so I need to time out the loop.

I've tried to research the web how to use a timer to achieve this but
none of the examples I found could help, plus im kind newb on vb and
vb.net. Lets say this is my first more serious vb.net program :)

Any sugestions?? Any help would be highly appreciated.

Thanks in advance

Joao

Oct 4 '07 #1
4 6802
On Oct 4, 7:33 am, joaotsetsemo...@gmail.com wrote:
hello everyone.

Im trying to time out a loot after a certain time. Probably 5 to 10
minutes.

I have the following function

Private Sub processFileCreation(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim strFilename As String = "c:\web\example.mdb"
Do
Loop While System.IO.File.Exists(strFilename) And
isFileOpen(strFilename)
writeDatabase()

End Sub

This function is being called when it fires the event "created" of a
filewatcher. The file "example.mdb" is being FTPed to the folder. The
loop is to verify if the file is completed written on disk to avoid
exceptions. Is a big file that could take 5 minutes to FTP it that
why I need this loop. Im trying to avoid an infinite loop if some user
has the file open, or if the file is being used by any other software,
so I need to time out the loop.

I've tried to research the web how to use a timer to achieve this but
none of the examples I found could help, plus im kind newb on vb and
vb.net. Lets say this is my first more serious vb.net program :)

Any sugestions?? Any help would be highly appreciated.

Thanks in advance

Joao
Probably the simplest way would be to execute the method that does the
loop in a seperate thread, and then use the Join method to wait for it
to finish or a timeout to expire.

Here's a sample console project demonstrating the process:

/////////////////////
Imports System.Threading

Module Module1

Sub Main()

Console.WriteLine("Starting thread...")

Dim t As New Thread(AddressOf DoTheWork)
t.Start()

Console.WriteLine("Thread starting successfully")

'// Do anything else you might need to do
'// while the thread is running
Console.WriteLine("Other work is being done...")

'// Block until thread completion or timeout (in milliseconds)
t.Join(2000)

'// Check to see if the timeout expired or
'// the thread finished
If t.IsAlive Then
Console.WriteLine("Timeout expired, aborting thread...")
'// Kill the thread
t.Abort()
Else
Console.WriteLine("Thread completed successfully")
End If

Console.Read()

End Sub

Public Sub DoTheWork()
Try
'// Create an infinite loop
While True
Console.WriteLine(" Thread is working...")
'// Pretend we are working
Thread.Sleep(250)
End While
Catch ex As ThreadAbortException
'// Do any cleanup here
Console.WriteLine("Thread Aborted")
End Try
End Sub

End Module
/////////////////////

Thanks,

Seth Rowe

Oct 4 '07 #2


jo*************@gmail.com wrote:
hello everyone.

Im trying to time out a loot after a certain time. Probably 5 to 10
minutes.

I have the following function

Private Sub processFileCreation(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim strFilename As String = "c:\web\example.mdb"
Do
Loop While System.IO.File.Exists(strFilename) And
isFileOpen(strFilename)
writeDatabase()

End Sub

This function is being called when it fires the event "created" of a
filewatcher. The file "example.mdb" is being FTPed to the folder. The
loop is to verify if the file is completed written on disk to avoid
exceptions. Is a big file that could take 5 minutes to FTP it that
why I need this loop. Im trying to avoid an infinite loop if some user
has the file open, or if the file is being used by any other software,
so I need to time out the loop.

I've tried to research the web how to use a timer to achieve this but
none of the examples I found could help, plus im kind newb on vb and
vb.net. Lets say this is my first more serious vb.net program :)

Any sugestions?? Any help would be highly appreciated.

Thanks in advance

Joao
If you dont want to use a thread, maybe just create a timer, set it to
10 min or whatever on the interval, and do something like this
<code written in notepad>

dim strfilename as .....
dim myTimeOutTimer as new timer
myTimeOutTimer.Interval = 10000 '(Example Time - change it)
myTimeOutTimer.Enabled = True

do
<your code here>
loop while <all ur stuffand myTimeOutTimer.Enabled = True
and in the timer event...just put myTimerOutTimer.Enabled = false.
fyi im a newbie.

M.
Oct 4 '07 #3
On Oct 4, 2:44 pm, Miro <miron...@beero.netwrote:
joaotsetsemo...@gmail.com wrote:
hello everyone.
Im trying to time out a loot after a certain time. Probably 5 to 10
minutes.
I have the following function
Private Sub processFileCreation(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim strFilename As String = "c:\web\example.mdb"
Do
Loop While System.IO.File.Exists(strFilename) And
isFileOpen(strFilename)
writeDatabase()
End Sub
This function is being called when it fires the event "created" of a
filewatcher. The file "example.mdb" is being FTPed to the folder. The
loop is to verify if the file is completed written on disk to avoid
exceptions. Is a big file that could take 5 minutes to FTP it that
why I need this loop. Im trying to avoid an infinite loop if some user
has the file open, or if the file is being used by any other software,
so I need to time out the loop.
I've tried to research the web how to use a timer to achieve this but
none of the examples I found could help, plus im kind newb on vb and
vb.net. Lets say this is my first more serious vb.net program :)
Any sugestions?? Any help would be highly appreciated.
Thanks in advance
Joao

If you dont want to use a thread, maybe just create a timer, set it to
10 min or whatever on the interval, and do something like this
<code written in notepad>

dim strfilename as .....
dim myTimeOutTimer as new timer
myTimeOutTimer.Interval = 10000 '(Example Time - change it)
myTimeOutTimer.Enabled = True

do
<your code here>
loop while <all ur stuffand myTimeOutTimer.Enabled = True

and in the timer event...just put myTimerOutTimer.Enabled = false.

fyi im a newbie.

M.- Hide quoted text -

- Show quoted text -
I would like to thank to both of you who posted messages to help me.

I follow Seth's sugestion and fitted perfectly for what I wanted. Just
finished now my first windows service.

thanks once again

Joao

Oct 4 '07 #4
jo*************@gmail.com wrote:
On Oct 4, 2:44 pm, Miro <miron...@beero.netwrote:
>joaotsetsemo...@gmail.com wrote:
>>hello everyone.
Im trying to time out a loot after a certain time. Probably 5 to 10
minutes.
I have the following function
Private Sub processFileCreation(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim strFilename As String = "c:\web\example.mdb"
Do
Loop While System.IO.File.Exists(strFilename) And
isFileOpen(strFilename)
writeDatabase()
End Sub
This function is being called when it fires the event "created" of a
filewatcher. The file "example.mdb" is being FTPed to the folder. The
loop is to verify if the file is completed written on disk to avoid
exceptions. Is a big file that could take 5 minutes to FTP it that
why I need this loop. Im trying to avoid an infinite loop if some user
has the file open, or if the file is being used by any other software,
so I need to time out the loop.
I've tried to research the web how to use a timer to achieve this but
none of the examples I found could help, plus im kind newb on vb and
vb.net. Lets say this is my first more serious vb.net program :)
Any sugestions?? Any help would be highly appreciated.
Thanks in advance
Joao
If you dont want to use a thread, maybe just create a timer, set it to
10 min or whatever on the interval, and do something like this
<code written in notepad>

dim strfilename as .....
dim myTimeOutTimer as new timer
myTimeOutTimer.Interval = 10000 '(Example Time - change it)
myTimeOutTimer.Enabled = True

do
<your code here>
loop while <all ur stuffand myTimeOutTimer.Enabled = True

and in the timer event...just put myTimerOutTimer.Enabled = false.

fyi im a newbie.

M.- Hide quoted text -

- Show quoted text -

I would like to thank to both of you who posted messages to help me.

I follow Seth's sugestion and fitted perfectly for what I wanted. Just
finished now my first windows service.

thanks once again

Joao

Seth has been using vb waaaay longer than me. Take his examples over
mine anyday!

cheers'

M.
Oct 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
4
by: coolsti | last post by:
I am aware of the setInterval and setTimeout functions for Javascript, but I can't seem to find an example that lets me do what I need to. I have a script that needs to wait until a certain...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
5
by: Flack | last post by:
Hey guys, Here is what I am trying to achieve: I have a grid, and every once in a while the grid will receive a message to add a new row and highlight it (change the backcolor) for five...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
24
by: asincero | last post by:
Would it be considered good form to begin every method or function with a bunch of asserts checking to see if the parameters are of the correct type (in addition to seeing if they meet other kinds...
4
by: sigloiv | last post by:
Alright, this is my first post here, and I'm the most ignorant coder one may meet (I've only started a few months ago, and I rarely have time to learn anything new), but, as a class project, I'm...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.