5 Replies - 482 Views - Last Post: 30 November 2012 - 05:58 PM Rate Topic: -----

#1 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Use Sleep On Only 1 Form

Posted 29 November 2012 - 01:10 PM

Is is possible to use sleep and only have it sleep the one form? I'm attempting to slow down a webbrowsers redirection speed and need to make the 1 form that houses the webbrowser to be slowed down. However, I need the other forms to still process at regular speed.

Can anyone help?

This is my code:
Sub redirecting() Handles Webbrowser1.Navigating
	System.Threading.Thread.Sleep(10000)
End Sub



Is it possible to run the .Navigating command on it's own thread? Not the whole form, but the .Navigating command.

Is This A Good Question/Topic? 0
  • +

Replies To: Use Sleep On Only 1 Form

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,194
  • Joined: 02-June 10

Re: Use Sleep On Only 1 Form

Posted 29 November 2012 - 07:18 PM

Sleep is for a thread, not an object (and a form is an object of the Form class).

If you want it to only affect one form you'll need to open other form on a new thread.

But let me tell you what I tell most people:
Thread.Sleep is evil and 99% of the use of it by rookies is wrong and won't do what you think.

It sleeps the entire thread. All of it. REsponse to events, response to GUI interaction, repainting of itself. Everything.
It is Thread.Sleep(10000) not Thread.WaitAroundAwhileButContinueToDoAllThatBackgroundStuff(10000)
If you sleep a form for 10 seconds like that the user will think the program is locked up and kill it with task manager.
Was This Post Helpful? 1
  • +
  • -

#3 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Use Sleep On Only 1 Form

Posted 30 November 2012 - 01:33 PM

View PosttlhIn`toq, on 29 November 2012 - 07:18 PM, said:

Sleep is for a thread, not an object (and a form is an object of the Form class).

If you want it to only affect one form you'll need to open other form on a new thread.

But let me tell you what I tell most people:
Thread.Sleep is evil and 99% of the use of it by rookies is wrong and won't do what you think.

It sleeps the entire thread. All of it. REsponse to events, response to GUI interaction, repainting of itself. Everything.
It is Thread.Sleep(10000) not Thread.WaitAroundAwhileButContinueToDoAllThatBackgroundStuff(10000)
If you sleep a form for 10 seconds like that the user will think the program is locked up and kill it with task manager.

I need it for a very specific reason. I need it to prevent any more interaction with the webserver for a set amount of seconds. Then, after the application finishes sleeping for the set number of seconds, resume interaction as if nothing happened. If you have a better way to do this, please, by all means, offer it up.
Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 769
  • Joined: 19-October 11

Re: Use Sleep On Only 1 Form

Posted 30 November 2012 - 01:42 PM

As tlhIn`toq explained, you can't halt the form, but you can pause the desired action. Take a look on Naviagting event, and re-think what you are trying to achieve. If you want to wait before you Navigate to some site, then just put Threading.Thread.Sleep(XXXX) 'XXXX in milliseconds before you call WebBrowser1.Navigate("http://destination.url.com"). But again, blocking the GUI and everything else is not smart move. You can have timers, backgroundworkers,...
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,194
  • Joined: 02-June 10

Re: Use Sleep On Only 1 Form

Posted 30 November 2012 - 01:45 PM

By 'interaction' I assume you mean not let the user send more requests.

I'd
  • set the browser component to .Enabled = false; that way the user can't do anything with it, but the thread isn't stopped.
  • start a System.Forms.Timer for 10 seconds
  • Then at the Timer.TIck event handler (end of 10 seconds) set the enabled back to true.

Was This Post Helpful? 0
  • +
  • -

#6 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Use Sleep On Only 1 Form

Posted 30 November 2012 - 05:58 PM

View PosttlhIn`toq, on 30 November 2012 - 01:45 PM, said:

By 'interaction' I assume you mean not let the user send more requests.

I'd
  • set the browser component to .Enabled = false; that way the user can't do anything with it, but the thread isn't stopped.
  • start a System.Forms.Timer for 10 seconds
  • Then at the Timer.TIck event handler (end of 10 seconds) set the enabled back to true.

No, i mean not letting the controller send any more requests and then resume interaction with the server shortly after. Meaning it completes a partial dataupload, idles around & then finishes the dataupload. Effectively freezing the action.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1