Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

The program I am creating needs to have a delay in opening the main form.

 

The program starts and tries to read default settings from a file, if these settings are not found an error message comes up, and the setup window shows up to enter the values in manually. This all needs to be done before the main form pops up. I put the code for detecting these conditions in the Main forms load event.

 

I know there was stuff in VB6 such as SetWaitableTimer and such. But in that function it used DoEvents, where did that go in VB .net? What is there to use now to stop the program temporarily until a certain condition is met???

Posted

two possibilities:

 

1 - I guess you open a Dialog to set these values you need when they aren't set. you could stop the prog by showing this Dialog with MySettingsDialog.ShowDialog(). this would cause the app to wait until the Dialog is closed again.

 

2. - the "dirty" possibility would be writing a loop which runs until the settings are set - with a Threading.Thread.Sleep(500) call at the end which sends the current app to sleep for half a second before the loop is entered again, checking if the values are set now and exit the loop if they if not run the loop etc....

 

Hope this helps!

 

Andreas

  • *Experts*
Posted
DoEvents in .NET is System.Windows.Forms.Application.DoEvents(), but most of the time you can just use Application.DoEvents().
Posted

Thanks for the help so far. I am thinking of headin in the route of the dialog box approach.

 

But before i do all that, there is not equivalence in VB.net with commands like SetWaitableTimer or anything like it that will pause the program until a condition has passed. I have hunted for code for VB.net with no results.

Posted

you can write something like this - but as far as I know there's no vb6 SetWaitableTimer-Function in vb.NET...

 

an example to fake this behavior:

Dim ExitLoop as Boolean = False

While Not ExitLoop
   Application.DoEvents()
   Threading.Thread.Sleep(500)
End While

..but you have to make sure that at some point the loop will be exited (ExitLoop = True)!! So the best way would be declaring ExitLoop in the Form (not in the Function..) and set it to true from the outside at some point.

Posted

Thank you alot for the help with that bit of code. It was simple but I am so used to the old ways of VB. Anyways i found that when i used the code you suggested there were some *small* delays when typing or selecting files in dialog boxes. So if you remove the line ----> Threading.Thread.Sleep(500) <---- it all runs smoothly.

 

The ExitLoop = true is in the close event in the form i load

 

Dim ExitLoop as Boolean = False

While Not ExitLoop
   Application.DoEvents()
End While

Posted

Yes, but your processor will be used for the full 100% (running through the waiting loop without any pauses) while the user gives in the setup data.

I would advice you to work with the showdialogue methode, or figure out if it is possible to run the form in which you give in the setup data on a thread, seperate from the thread on which the Main form runs...

qrt
Posted

If you put an empty loop, it locks up the program because it is using 100% of the processor and never leaves. With the original code you would go to click but the program would be sleeping and whenever you would want to do something with the form there would be endless little pauses and freezes. By getting rid of that it does not freeze pause or even slow the computer down. If the program was using 100% of the processor you would not be able to click buttons without any delay or type text without there being a pause between what you type and what shows up.

 

I was thinking that too, but try it, and see what happens, you may be surprized.

 

It almost seems like that statement is saying, while ExitLoop is false pause the program, and after that does not loop, just waits for the exit loop to change to true

Posted

Don't sure it good or not

but I just try loop with

 

DoEvents

Sleep 1

 

seem it work. a little bit delay compare run without "sleep"

but CPU never peak.

 

(without sleep my process end in 11227 TickCount

with sleep my process end in 12786 TickCount)

 

But what I actually want (I think tonofstell also) is some code which can act as "Timer" control. Timer control never eat CPU and come back to do the work at adjustable period. Just want something like that in Code.

  • 4 weeks later...
Posted

There should never be any need to sit and wait for something to happen. Instead, start that something and exit - and the end of the 'something' run the next step, eg (pseudo):

 

Startup Form = frmSetup

frmSetup_Unload (handles MyBase.Closed)

Load frmMain

 

or use Derek Stone's idea

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...