opening a window from another's load event

B

Bernie Yaeger

I want to open a window (the called window) - and perhaps run a progressbar,
etc - from a calling window's load event. The calling window is loading a
large datatable before it completes its load event.

The calling window itself is a child window in an mdi app. I'm having a
terrible time trying to do this, as the called window never fully opens
unless it's called via showdialog, but this is not what I want, because I
want it to close when the progressbar completes (or when the calling window
finally loads, which is the same thing).

Thanks for any help.

Bernie Yaeger
 
C

Cor

Hi Bernie,

I would make a seperate thread to load that dataset, and not succeed in
getting that fill to give information use "on and off" gif's that are
changed from throwed events every 5 seconds in the the thread.

I have here pasted some code that Armin did made for this, I still did not
check it, but I think it is a good start for your question.

And before you ask it, you can kill a thread with "myThread.abort"

I hope you a little bit?

Cor

\\\By Armin Zingler
In a new project, add a button to the Form. Also add the following code:

Private m_Thread As MyThread

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub
////
Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class
///
 
B

Bernie Yaeger

Hi Cor,

Thanks very much. I will be testing this code today.

Thanks again,

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top