What is the best way to do this...

  • Thread starter Thread starter PiotrKolodziej
  • Start date Start date
P

PiotrKolodziej

Hi
1. app start
2. user clicks Login Button
3. Application connects to the serwer ( check login and download dir list -
1mb )
Problem is when application is executing method responsible for dooing 3.
It takes time and i dont want my app to be "lagged".
I tought that i can create thread for this task. When thread will finish the
only thing that remains is to fill treewiev in main thread ( so i need to
invoke one method ).
is this good solution?
 
Hello PiotrKolodziej,

This is reasonable solution, because main thread is not that place where
task shoul be run

In you main window you can show the progress bar informing your user how
long is remained to download

P> Hi
P> 1. app start
P> 2. user clicks Login Button
P> 3. Application connects to the serwer ( check login and download dir
P> list -
P> 1mb )
P> Problem is when application is executing method responsible for
P> dooing 3.
P> It takes time and i dont want my app to be "lagged".
P> I tought that i can create thread for this task. When thread will
P> finish the
P> only thing that remains is to fill treewiev in main thread ( so i
P> need to
P> invoke one method ).
P> is this good solution?
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
PiotrKolodziej,

Well, it's your only solution really. How come it takes so long to
download the directory list?

But generally, yes, you should invoke another thread to do this and then
notify your main app when it is complete.

Hope this helps.
 
Thank you both.
I also need progress bar because of long time that is takes.
I tought i can call thread. Inside this thread create instance of
ProgressBarForm to display progress.
When login and download will complete i will dispose this form and Invoke
another method to let Main thread know that job is done.

Iam writing this because i have still in my mind other solution. Instead of
calling thread i can explicitly create instance of another Form ( with
progress bar and download methods ) and let the Main form know from new this
new Form if the job is done.

I'd like to know your opinion.
PK
 
PiotrKolodziej said:
Thank you both.
I also need progress bar because of long time that is takes.
I tought i can call thread. Inside this thread create instance of
ProgressBarForm to display progress.
When login and download will complete i will dispose this form and Invoke
another method to let Main thread know that job is done.

Iam writing this because i have still in my mind other solution. Instead of
calling thread i can explicitly create instance of another Form ( with
progress bar and download methods ) and let the Main form know from new this
new Form if the job is done.

Simply creating a second form will not make a difference if the
download is still happening on the UI thread. If the UI thread is
waiting for the download, it cannot be redrawing anything on the
screen, so your application will freeze.

No matter how you slice it, you need a background thread if you want
your application to remain responsive (and that includes drawing a
progress bar).
 
Simply creating a second form will not make a difference if the
download is still happening on the UI thread. If the UI thread is
waiting for the download, it cannot be redrawing anything on the
screen, so your application will freeze.

No matter how you slice it, you need a background thread if you want
your application to remain responsive (and that includes drawing a
progress bar).

I didn't mention that i will wait for the Second form to complete. I might
simply Show() not ShowDialog(), and let the Main thread go...
 
PiotrKolodziej said:
I didn't mention that i will wait for the Second form to complete. I might
simply Show() not ShowDialog(), and let the Main thread go...

I doesn't matter whether you use Show() or ShowDialog(). The two forms
are both running on the UI thread. If you do the download from any form
you will block the entire UI.
 

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

Back
Top