By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

When I call form.show in a thread it close when the thread completes.

P: n/a
How do I keep the form up.
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
How do I keep the form up.

Nov 21 '05 #2

P: n/a
That worked. Thanks

My second form was taking focus away from the first form when it was popping
up. So I put it on a seperate thread, but when the form.show fired off in
the thread it immediately closed. .showdialog is keeping it up.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is
closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
How do I keep the form up.


Nov 21 '05 #3

P: n/a
Any idea on why the form might take so long to paint. I know in Foxpro if
you scrolled thru the items of a listbox before showing it, that the form
would come up a lot faster.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is
closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
How do I keep the form up.


Nov 21 '05 #4

P: n/a
How many items are you putting in the listbox? How long is long? Someone
was asking about the time it took to populate 12000 records in a listbox
yesterday or the day before. I don't know of any way to speed it up if that
is what's taking so long. If you post some simplified code for form2 that
shows the problem we may be able to help.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Any idea on why the form might take so long to paint. I know in Foxpro if
you scrolled thru the items of a listbox before showing it, that the form
would come up a lot faster.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is
closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
How do I keep the form up.



Nov 21 '05 #5

P: n/a
Public Class frm_PCPlist
Public dt_PCP As New DataTable
Friend m_PCPThread As Thread
Public Sub New()
'/// <summary>
'/// To speed up the process of displaying the list of providers.
'/// create a seperate thread to create the datatable in the
background
'/// </summary>
Dim ts1 As ThreadStart = New ThreadStart(AddressOf preLoadPCP)
m_PCPThread = New Thread(ts1)
m_PCPThread.IsBackground = True
m_PCPThread.Start()
End sub

Private Sub preLoadPCP()
'/// Get the provider list and load the lsit box on the PCPlist form
Dim PCPSql As String = _
"Select rtrim(provider) + ' | ' + rtrim(plast_nme) +', '
+ " _
& "rtrim(pfirst_nme) as name, provider from provider
order by plast_nme,pfirst_nme"
Dim PCPCmd As New SqlCommand(PCPSql, conn_EMC)
Dim PCPAdptr As New SqlDataAdapter(PCPCmd)
PCPAdptr.Fill(dt_PCP)
PCPList.DataSource = dt_PCP
PCPList.DisplayMember = "name"
PCPList.ValueMember = "provider"
End sub

Form1 instantiates this form and does not show it until the thread stops.

But once the thread stops, the form takes a few seconds to show. The
records - about 12 thousand have already been loaded into the datatable. so
it is not like the user opened the form directly and then got the data. I'd
understand the delay then. But the data is already loaded. So my guess is
the painting of the form.

-Phil

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
How many items are you putting in the listbox? How long is long? Someone
was asking about the time it took to populate 12000 records in a listbox
yesterday or the day before. I don't know of any way to speed it up if
that is what's taking so long. If you post some simplified code for form2
that shows the problem we may be able to help.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Any idea on why the form might take so long to paint. I know in Foxpro if
you scrolled thru the items of a listbox before showing it, that the form
would come up a lot faster.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is
closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
How do I keep the form up.



Nov 21 '05 #6

P: n/a
My guess would be it is doing the binding of actually loading the items into
the listbox. I don't have a solution for your problem though. The only
thing I can think of is to do some heavy customization of the listbox so
that you only load the data in the listbox that is shown at one time. If
you can see 6 items at one time, just show the first six items. When the
user moves up or down in the list, add/remove items as they move. That way
you won't have the lag time. You would be basically writing your own
databindings. If you load a subset of the data, say 100 records, does it
work fasters? To test this bind the listbox to a DataView of the datatable
instead of the datatable itself.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl...
Public Class frm_PCPlist
Public dt_PCP As New DataTable
Friend m_PCPThread As Thread
Public Sub New()
'/// <summary>
'/// To speed up the process of displaying the list of providers.
'/// create a seperate thread to create the datatable in the
background
'/// </summary>
Dim ts1 As ThreadStart = New ThreadStart(AddressOf preLoadPCP)
m_PCPThread = New Thread(ts1)
m_PCPThread.IsBackground = True
m_PCPThread.Start()
End sub

Private Sub preLoadPCP()
'/// Get the provider list and load the lsit box on the PCPlist
form
Dim PCPSql As String = _
"Select rtrim(provider) + ' | ' + rtrim(plast_nme) +', '
+ " _
& "rtrim(pfirst_nme) as name, provider from provider
order by plast_nme,pfirst_nme"
Dim PCPCmd As New SqlCommand(PCPSql, conn_EMC)
Dim PCPAdptr As New SqlDataAdapter(PCPCmd)
PCPAdptr.Fill(dt_PCP)
PCPList.DataSource = dt_PCP
PCPList.DisplayMember = "name"
PCPList.ValueMember = "provider"
End sub

Form1 instantiates this form and does not show it until the thread stops.

But once the thread stops, the form takes a few seconds to show. The
records - about 12 thousand have already been loaded into the datatable.
so it is not like the user opened the form directly and then got the data.
I'd understand the delay then. But the data is already loaded. So my guess
is the painting of the form.

-Phil

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
How many items are you putting in the listbox? How long is long?
Someone was asking about the time it took to populate 12000 records in a
listbox yesterday or the day before. I don't know of any way to speed it
up if that is what's taking so long. If you post some simplified code
for form2 that shows the problem we may be able to help.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Any idea on why the form might take so long to paint. I know in Foxpro
if you scrolled thru the items of a listbox before showing it, that the
form would come up a lot faster.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Need a little more information to be specific to what you're doing, but
Form.ShowDialog will not allow the thread to close until the form is
closed.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
> How do I keep the form up.
>



Nov 21 '05 #7

P: n/a
Well that speeds it up alot. I am not sure how to go about adding recs as
the move. The strange thing is that I don't try to show the form until the
data is there. So it must have to do with how much data is in the listbox.
It either doesn't bind the datatable to each item until it paints or the
amount of data in the table affects how quickly it loads.

My theory atleast.

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ut*************@TK2MSFTNGP12.phx.gbl...
My guess would be it is doing the binding of actually loading the items
into the listbox. I don't have a solution for your problem though. The
only thing I can think of is to do some heavy customization of the listbox
so that you only load the data in the listbox that is shown at one time.
If you can see 6 items at one time, just show the first six items. When
the user moves up or down in the list, add/remove items as they move.
That way you won't have the lag time. You would be basically writing your
own databindings. If you load a subset of the data, say 100 records,
does it work fasters? To test this bind the listbox to a DataView of the
datatable instead of the datatable itself.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl...
Public Class frm_PCPlist
Public dt_PCP As New DataTable
Friend m_PCPThread As Thread
Public Sub New()
'/// <summary>
'/// To speed up the process of displaying the list of providers.
'/// create a seperate thread to create the datatable in the
background
'/// </summary>
Dim ts1 As ThreadStart = New ThreadStart(AddressOf preLoadPCP)
m_PCPThread = New Thread(ts1)
m_PCPThread.IsBackground = True
m_PCPThread.Start()
End sub

Private Sub preLoadPCP()
'/// Get the provider list and load the lsit box on the PCPlist
form
Dim PCPSql As String = _
"Select rtrim(provider) + ' | ' + rtrim(plast_nme) +',
' + " _
& "rtrim(pfirst_nme) as name, provider from provider
order by plast_nme,pfirst_nme"
Dim PCPCmd As New SqlCommand(PCPSql, conn_EMC)
Dim PCPAdptr As New SqlDataAdapter(PCPCmd)
PCPAdptr.Fill(dt_PCP)
PCPList.DataSource = dt_PCP
PCPList.DisplayMember = "name"
PCPList.ValueMember = "provider"
End sub

Form1 instantiates this form and does not show it until the thread stops.

But once the thread stops, the form takes a few seconds to show. The
records - about 12 thousand have already been loaded into the datatable.
so it is not like the user opened the form directly and then got the
data. I'd understand the delay then. But the data is already loaded. So
my guess is the painting of the form.

-Phil

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
How many items are you putting in the listbox? How long is long?
Someone was asking about the time it took to populate 12000 records in a
listbox yesterday or the day before. I don't know of any way to speed
it up if that is what's taking so long. If you post some simplified
code for form2 that shows the problem we may be able to help.

Chris

"PAPutzback" <Ph**************@Insightbb.com> wrote in message
news:OF*************@TK2MSFTNGP11.phx.gbl...
Any idea on why the form might take so long to paint. I know in Foxpro
if you scrolled thru the items of a listbox before showing it, that the
form would come up a lot faster.
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
> Need a little more information to be specific to what you're doing,
> but Form.ShowDialog will not allow the thread to close until the form
> is closed.
>
> Chris
>
> "PAPutzback" <Ph**************@Insightbb.com> wrote in message
> news:ev**************@TK2MSFTNGP09.phx.gbl...
>> How do I keep the form up.
>>
>
>



Nov 21 '05 #8

P: n/a
"PAPutzback" <Ph**************@Insightbb.com> schrieb:
How do I keep the form up.

Always create your forms in your application's main UI thread. Instance
members of Windows Forms forms and controls are not safe for multithreading,
so accessing them directly can cause problems. In addition to that, your
forms need a message pump which is normally provided by the app's main UI
thread.

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.