Results 1 to 10 of 10

Thread: Ho do I create a "Please Wait..." window behind a process...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

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

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    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.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    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?

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Re: Ho do I create a "Please Wait..." window behind a process...

    Quote Originally Posted by Shaggy Hiker View Post
    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.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2012
    Posts
    221

    Re: Ho do I create a "Please Wait..." window behind a process...

    Quote Originally Posted by Shaggy Hiker View Post
    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
  •  



Click Here to Expand Forum to Full Width