-
Dec 6th, 2014, 03:24 PM
#1
Thread Starter
Addicted Member
Ho do I create a "Please Wait..." window behind a process...
Hello,
I have a vb 2010 access database application and I am interested to create a window that says something like: "Project loading. Please wait...".
This is because there are some calculations done and on some slow computers it takes about 4 seconds to load.
My problem is that I wouldn't want to move any code. I suppose I could move an entire function into a newly created form but I would like to avoid this if possible.
Basically I just want to show up a window until a certain process is done. If possible to show this window with different messages for different processes.
Is there anything dedicated that I should be looking into?
Thx...
-
Dec 6th, 2014, 03:48 PM
#2
Re: Ho do I create a "Please Wait..." window behind a process...
Run a background worker. While BackgroundWorker.Work Is Running 'Show what you want
When it's done, stop it and show the data. Simples. Well that's the logic behind it.
-
Dec 6th, 2014, 05:44 PM
#3
Re: Ho do I create a "Please Wait..." window behind a process...
Show the window non-modally using .Show rather than .ShowDialog. It doesn't have to be harder than that.
My usual boring signature: Nothing
-
Dec 7th, 2014, 04:59 AM
#4
Thread Starter
Addicted Member
Re: Ho do I create a "Please Wait..." window behind a process...
Thx. Good ideas. I will try both oh these and see how it behaves.
Cheers
-
Dec 7th, 2014, 04:35 PM
#5
Thread Starter
Addicted Member
Re: Ho do I create a "Please Wait..." window behind a process...
Hello again,
I didn't like the .Show method because I don't want the user to be able to do anything while the process runs so I decided to go with the Background Worker. Now, the simplest way to do it as I figured it, without changing any significant code, would be the following (I created a separate app for this example):
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
'Suppose this would be the process that takes a long time
For i = 0 To 50
Label1.Text = i
Label1.Refresh()
System.Threading.Thread.Sleep(100)
Next
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'Show the "Please wait" form. Here the user can't do anything but wait
Form2.ShowDialog()
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Form2.Close()
End Sub
End Class
I think this is what I need. But for some reason the form2 doesn't automatically get closed at the end. Is there anything I'm missing.
-
Dec 8th, 2014, 12:16 PM
#6
Thread Starter
Addicted Member
Re: Ho do I create a "Please Wait..." window behind a process...
Can anybody please help? Could I write something else to close this form by code when the background worker finishes?
-
Dec 8th, 2014, 04:04 PM
#7
Re: Ho do I create a "Please Wait..." window behind a process...
Try Me.Close rather than Form2.close. The former closes the current instance, whatever it is, while the latter closes the default instance of Form2, which may or may not be the instance you are looking at.
My usual boring signature: Nothing
-
Dec 8th, 2014, 04:24 PM
#8
Thread Starter
Addicted Member
Re: Ho do I create a "Please Wait..." window behind a process...
Originally Posted by Shaggy Hiker
Try Me.Close rather than Form2.close. The former closes the current instance, whatever it is, while the latter closes the default instance of Form2, which may or may not be the instance you are looking at.
Doesn't work. The thing is at first it did close the form and then gave me an error but I can't remember what it was. And now it's just doing nothing.
-
Dec 8th, 2014, 06:02 PM
#9
Re: Ho do I create a "Please Wait..." window behind a process...
Can't you just run it again and see the error?
My usual boring signature: Nothing
-
Dec 9th, 2014, 01:03 AM
#10
Thread Starter
Addicted Member
Re: Ho do I create a "Please Wait..." window behind a process...
Originally Posted by Shaggy Hiker
Can't you just run it again and see the error?
I did that and it's just the same. Maybe I did something wrong then. Anyway, it doesn't work this way. The thing is that the background worker isn't finished until I manually close the form2 window.
I tried to close the window after the for...next sequence but it still doesn't work.
Any suggestions?
Last edited by ovi_gm; Dec 9th, 2014 at 02:47 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|