Results 1 to 8 of 8

Thread: Is there a delay() command of some sort in vb.net?

  1. #1

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366

    Is there a delay() command of some sort in vb.net?

    I need to delay program execution for a few seconds...

    i.e

    ' Do stuff here

    ' delay for 5 seconds

    ' continue here

    How can I do this?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. System.Threading.Thread.Sleep(666)

  3. #3

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Thanks, you're probly wondering why I would want to do this. Maybe you have a better idea. How can I run a loop until a service has been installed?

    i.e

    Dim sc as New ServiceController("MyService")

    do until sc.exists()\
    loop

    But I can't find anything similar in the real world...

  4. #4
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Look into the ServiceControlller's WaitForStatus functionality.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  5. #5

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Problem is an exception is thrown when I call the serviceController object.

    I wrote a function that returns true if no exception is thrown and false if an exception is thrown to check if the service is installed, but was wondering if there's a better way to do this...

  6. #6
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Can you give us some source code of what you are trying to do?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  7. #7

    Thread Starter
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Well,

    All I'm doing is installing some third party services, and then trying to start them once they are installed.

    The problem has been though that the app tries to start the service before its been installed. So If I create a service object i.e

    Dim sc as New ServiceController("MyService")

    And I try to reference the object, an exception is thrown.

    What I ultimately want to do is check if the service is installed without throwing an exception.

    But what I have done, which works is run a function that throws false if an exception occurs when it checks the service.

    Any better way to do this?

  8. #8
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Well, you could put a loop in there with some sleeps....

    ...try to create the ServiceController, catch any exceptions, if it excepted, sleep ten seconds and try again until you get success or a maximum amount of interations have occurred...
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

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