miscal

Hi,

My application includes accessing SQL server. The code specifies label text "connecting" BEFORE the connection opening line. in some cases, the lables presented on dialogs "please wait..". Still, since the computer is 'too fast' - the dialog is not shown because the computer reaches the showdialog line and before the dialog is shown it reaches to the connection opening line - and while waiting for the connection to be established, no dialog is shown...how can I fix it, that the dialog will be shown first, a delay of a few milisecs will be taken, and only then it will open the connection



Re: Windows Forms General presenting label text or showing dialog

Rizshe

Hi ya

You can use Timer control. It is pretty easy to use.

Here is the link

Cheers

Rizwan






Re: Windows Forms General presenting label text or showing dialog

VS_Programmer

You can also use the SLEEP function, which forces your program to pause for a while. Try this:

System.Threading.Thread.Sleep(number of milliseconds to wait);

For more info, see http://msdn2.microsoft.com/en-us/library/system.threading.thread.sleep(VS.71).aspx

Hope this helps





Re: Windows Forms General presenting label text or showing dialog

Ðãv? S. Â???????

One word: don't. Don't intentionally make your applications slower. It may be slower on your computer, but its quite noticeable on others. Leave your code as is, and the dialog will show on slower computers.

Its a horrible thing when you start talking about making your application slower. Intentionally. Unless you really do have a valid reason for doing so, don't, just don't. Your clients won't like you very much if they found out it was intentionally made slower.

Hope this helps.





Re: Windows Forms General presenting label text or showing dialog

miscal

I agree with you - I do not have intensions of making my application slower, the thing is - when it tries to establiush a connection to the server - the dialog won't show up - it look like it skips the "showdialog" and goes straight to the connection opening. For the user - it looks like the application halts (while it tries to establish a connection without informing the user). How can I make the dialog show up BEFORE going to the connection lines



Re: Windows Forms General presenting label text or showing dialog

VS_Programmer

Are you putting a button (yes, perhaps) in your dialog that the user presses to start the connection. If so, connect the call to the button clicked event.

Otherwise, fire the event on the dialogload event.

Hope this helps





Re: Windows Forms General presenting label text or showing dialog

Ðãv? S. Â???????

Post the section of code containing your ShowDialog() call.





Re: Windows Forms General presenting label text or showing dialog

miscal

the code for the button_click event:

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

.....

.....

Dialog4.ShowDialog()

.....

rest of the code

__________________________

The code of the dialog_load event:

Private Sub Dialog4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.ProgressBar1.Value = 20

Dim con As New SqlConnection("Data Source=datasource;Network Library=DBMSSOCN;Initial Catalog=db;User ID=usr;Password=pwd;connection timeout = 30")

Try

con.Open()

Catch ex As Exception

MsgBox("error", MsgBoxStyle.Exclamation, ex.Message)

Me.Close()

refound = False

Exit Sub

End Try

.....

rest of the dialog code...

There is the Burron_Click code, which sends to the Showdialog. Now the showdialog - WITHOUT SHOWING THE DIALOG - goes to the con.open.

Thanks,

Dror.





Re: Windows Forms General presenting label text or showing dialog

Ðãv? S. Â???????

Well, if your program is working fine, I don't see what the problem is. You really shouldn't make a delay. If you absolutely want your dialog to show for a set amount of time you can use the Thread.Sleep() method as stated in a previous post to make a delay for a set amount of milliseconds.

A few things to check though.
1. Make sure your button click event is actually linked to your button.
2. To help diagnose the problem above, is your connection actually connecting If not, that would tell you that #1 needs to be fixed.





Re: Windows Forms General presenting label text or showing dialog

miscal

well first - thanks for your reply.

The program is working just fine, but I do not want the user sit still with not knowing if the application is halted, or is it just trying to make a connection to the server (which it actually does). It does connect successfully.





Re: Windows Forms General presenting label text or showing dialog

Ðãv? S. Â???????

"but I do not want the user sit still with not knowing if the application is halted,"

If it executes instantly, I don't see what the problem is., unless it doesn't do anything aftwards. If that's the case, you should notify your user that the operation has completed then. After your line of code that makes the connection, possibly show a message box saying the operation completed successfully.





Re: Windows Forms General presenting label text or showing dialog

miscal

The problem is that the execution does not take place instantly, and in some cases - the user has to wait about 20-30 seconds till the connection is established. During the wait time - the user doesn't see anything happens.



Re: Windows Forms General presenting label text or showing dialog

VS_Programmer

That is a mighty hefty database call. What are you accessing that would need you to wait 20-30 seconds Your user still won't want to wait that long, even if they see the dialog. They will problably think the program froze.

You can also try calling the dialog's Initate() function, which should force it to redraw (and maybe appear);

Hope this helps





Re: Windows Forms General presenting label text or showing dialog

Ðãv? S. Â???????

Stupid me, I know why your dialog is not showing.

You're processing your connection in the LOAD event. This event occurs BEFORE the form is shown. Transfer all your code from the load event to your forms shown event. And it the code locks up your form, you will need to put your connection code on a separate thread.





Re: Windows Forms General presenting label text or showing dialog

miscal

well - good thinking - but still theconnection attempt is reached before the comuter manages to show the dialog. I've tried new thinking: when the button is clicked - I won't load any dialog, but change one of the lables to "Please Wait". still, this has to take place not on "Butoon_click" event - because on this event - the lable is not shown before the connection attempt, so I've entered the "label.text = 'please wait'" on the Button_MouseDown event. BUT, now there is smaller problem now: it happens when any mouse button is clicked, and I want it to happen when only LEFT button is clieckd. I've tried "Button_MouseLeftButtonDown" - but it seems that the event is not included in the existing namespace...