Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Hi,

i'm at a point where i need to wait 5 seconds befor contineuing,

how do i do that? :confused:

the question is. . . why do you need to wait 5 seconds?

are you waiting for some process to finish???

 

having a process wait a specific period of time to continue is poor practice. it leads to platform dependencies.

 

I am guessing you are looking to perform asynchonous processing. . .

 

look into Asynchronous Programming Overview in the help file!!!

It will make you a better programmer!

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

having a process wait a specific period of time to continue is poor practice. it leads to platform dependencies.

 

I can't see how. Perhaps you can elaborate for the benefit of those who do not know (like me). Thanks.

Posted

If you're waiting for something slower than your program, which is normally harware related, use Application.DoEvents().

 

It stops the program, makes sure everything is caught up, then continues. I remember having to use this when I was doing a LOT of reading/writing in collections from/to files (scanning 5,000 text documents for specific text, then grabbing the next word).

 

You also need to do this when displaying your graphics in a game loop. If it gets too complex.

  • *Experts*
Posted

I think the question is (again):

Why do you want to wait 5 seconds?

 

A solution can't be offered if we don't know the problem.

 

If you just want to wait 5 seconds to see who, then Sleep will work perfectly. If you're working around some issue, we'll need to know what it is to help.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

i have a program i run, and i read the output, it stays open if i don't close it with: Apache_Proc.CloseMainWindow()

but if i do it to soon, i cant read the output.

Private Sub ap_test()
       With Args
           .FileName = sApache_dir & "\bin\apache.exe"
           .Arguments = "-t -n """ & sApache_service & """ "
           .UseShellExecute = False
           .RedirectStandardError = True
           .RedirectStandardOutput = True
           .WindowStyle = ProcessWindowStyle.Hidden
       End With
       Apache_Proc = Process.Start(Args)
       System.Threading.Thread.Sleep(5000)
       Try
           Apache_Proc.CloseMainWindow()
       Catch ex As Exception
           'do nothing
       End Try
       Dim sData As String = Apache_Proc.StandardError.ReadLine
       If sData = "Syntax OK" Then
           txtStatus.Text = txtStatus.Text & vbCrLf & "[" & GetTime() & "] " & "Apache Test result: Syntax OK"
           If Me.Visible = False Then
               SysTray.ShowBalloon(NotifyIcon2.NotifyIcon2.EBalloonIcon.Info, "Apache Test result: Syntax OK", "ApacheMon", 5)
           End If
       Else
           txtStatus.Text = txtStatus.Text & vbCrLf & "[" & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second & "] " & "Apache Test result: Error found, please check your config"
           If Me.Visible = False Then
               SysTray.ShowBalloon(NotifyIcon2.NotifyIcon2.EBalloonIcon.Info, "Apache Test result: Error found, please check your config", "ApacheMon", 5)
           End If
       End If
   End Sub

this is what i have now, and yes on a slow computer 5 sec maybe to litle, but i see no other way(if you do, feel free to comment)

Posted

Apache_Proc = Process.Start(Args)
System.Threading.Thread.Sleep(5000)

wouldnt this work?

 

Apache_Proc = Process.Start(Args)
while not Apache_Proc.HasExited do
Application.DoEvents()

 

 

this is what i have now, and yes on a slow computer 5 sec maybe to litle, but i see no other way(if you do, feel free to comment)

JABE. . are you paying attention? Perhaps Platform Dependency is the wrong term as opposed to Hardware Dependency. . .

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted
No' date=' sins it doesnt close by itself[/quote']

Apache_Proc = Process.Start(Args)

while not Apache_Proc.HasExited do

Application.DoEvents()

 

Here is how I see it.

 

Start a thread and in the thread...

 

while not Apache_Proc.HasExited or something like this... (while your output is not ready) Application.DoEvents

 

And outside the While... do the action needed for your outpout.

 

-Stay-ZeN-

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...