threading

G

Grant Merwitz

Hi

I am trying to thread a large process to show the user a 'processing' gif
while this thread loads

what i have done, is create a submit_click method and set it to be a thread.
In the start of the thread i hide the main panel on the page, and show a
hidden image ('loading.gif')
I then create a threadstart and perform my larger process.
At the end of this larger process, i hide the 'loading.gif' and display the
main panel again.

The image shows fine at the beginning of the large process, but doesn't hide
when it is finished ... why?

sample code:

[MTAThread]
private void Submit_Click(object Sender, EventArgs e)
{
//show the loading panel
MainPanel.Visible = false;
ImagePanel.Visible = true;

//Start the larger process
ThreadStart TS = new ThreadStart(PerformAuthorisation);
Thread workerThread = new Thread(TS);
Thread.Start();
}

[MTAThread]
private void PerformAuthorisation()
{
//large processing goes here

//Show the main panel again
MainPanel.Visible = true;
ImagePanel.Visible = false;
}

So, the loading panel is shown correctly in the first place, but the reverse
is never done.
Any ideas

TIA

Grant
 
K

Kevin Spencer

The nature of threads is this: Threads operate independently. What I mean by
that is, a Page class is instantiated when a Request comes from a client.
The Page class processes the Request and then is destroyed, all within a
matter of milliseconds. Now, when the Page class, in the process of
processing a Request, spawns another thread, the new thread has access to
all the properties of the class which spawned it -AS LONG AS THAT CLASS IS
ALIVE. Once the Page class terminates, it is terminated.

In other words, while this sort of thing works nicely in executables, where
state is constant, in ASP.Net, where state comes and goes in a heartbeat,
you need to account for the fact that state comes and goes in a heartbeat.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Grant Merwitz

ok, that makes sense. Thanks

So how can i achieve what i set out to do now.
Showing a loading page during a large process?



Kevin Spencer said:
The nature of threads is this: Threads operate independently. What I mean
by that is, a Page class is instantiated when a Request comes from a
client. The Page class processes the Request and then is destroyed, all
within a matter of milliseconds. Now, when the Page class, in the process
of processing a Request, spawns another thread, the new thread has access
to all the properties of the class which spawned it -AS LONG AS THAT CLASS
IS ALIVE. Once the Page class terminates, it is terminated.

In other words, while this sort of thing works nicely in executables,
where state is constant, in ASP.Net, where state comes and goes in a
heartbeat, you need to account for the fact that state comes and goes in a
heartbeat.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

Grant Merwitz said:
Hi

I am trying to thread a large process to show the user a 'processing' gif
while this thread loads

what i have done, is create a submit_click method and set it to be a
thread.
In the start of the thread i hide the main panel on the page, and show a
hidden image ('loading.gif')
I then create a threadstart and perform my larger process.
At the end of this larger process, i hide the 'loading.gif' and display
the main panel again.

The image shows fine at the beginning of the large process, but doesn't
hide when it is finished ... why?

sample code:

[MTAThread]
private void Submit_Click(object Sender, EventArgs e)
{
//show the loading panel
MainPanel.Visible = false;
ImagePanel.Visible = true;

//Start the larger process
ThreadStart TS = new ThreadStart(PerformAuthorisation);
Thread workerThread = new Thread(TS);
Thread.Start();
}

[MTAThread]
private void PerformAuthorisation()
{
//large processing goes here

//Show the main panel again
MainPanel.Visible = true;
ImagePanel.Visible = false;
}

So, the loading panel is shown correctly in the first place, but the
reverse is never done.
Any ideas

TIA

Grant
 
K

Kevin Spencer

Google "ASP.Net Progress"

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

Grant Merwitz said:
ok, that makes sense. Thanks

So how can i achieve what i set out to do now.
Showing a loading page during a large process?



Kevin Spencer said:
The nature of threads is this: Threads operate independently. What I mean
by that is, a Page class is instantiated when a Request comes from a
client. The Page class processes the Request and then is destroyed, all
within a matter of milliseconds. Now, when the Page class, in the process
of processing a Request, spawns another thread, the new thread has access
to all the properties of the class which spawned it -AS LONG AS THAT
CLASS IS ALIVE. Once the Page class terminates, it is terminated.

In other words, while this sort of thing works nicely in executables,
where state is constant, in ASP.Net, where state comes and goes in a
heartbeat, you need to account for the fact that state comes and goes in
a heartbeat.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

Grant Merwitz said:
Hi

I am trying to thread a large process to show the user a 'processing'
gif while this thread loads

what i have done, is create a submit_click method and set it to be a
thread.
In the start of the thread i hide the main panel on the page, and show a
hidden image ('loading.gif')
I then create a threadstart and perform my larger process.
At the end of this larger process, i hide the 'loading.gif' and display
the main panel again.

The image shows fine at the beginning of the large process, but doesn't
hide when it is finished ... why?

sample code:

[MTAThread]
private void Submit_Click(object Sender, EventArgs e)
{
//show the loading panel
MainPanel.Visible = false;
ImagePanel.Visible = true;

//Start the larger process
ThreadStart TS = new ThreadStart(PerformAuthorisation);
Thread workerThread = new Thread(TS);
Thread.Start();
}

[MTAThread]
private void PerformAuthorisation()
{
//large processing goes here

//Show the main panel again
MainPanel.Visible = true;
ImagePanel.Visible = false;
}

So, the loading panel is shown correctly in the first place, but the
reverse is never done.
Any ideas

TIA

Grant
 
R

Rutger Smit

Grant said:
Hi

I am trying to thread a large process to show the user a 'processing' gif
while this thread loads

what i have done, is create a submit_click method and set it to be a thread.
In the start of the thread i hide the main panel on the page, and show a
hidden image ('loading.gif')
I then create a threadstart and perform my larger process.
At the end of this larger process, i hide the 'loading.gif' and display the
main panel again.

The image shows fine at the beginning of the large process, but doesn't hide
when it is finished ... why?

sample code:

[MTAThread]
private void Submit_Click(object Sender, EventArgs e)
{
//show the loading panel
MainPanel.Visible = false;
ImagePanel.Visible = true;

//Start the larger process
ThreadStart TS = new ThreadStart(PerformAuthorisation);
Thread workerThread = new Thread(TS);
Thread.Start();
}

[MTAThread]
private void PerformAuthorisation()
{
//large processing goes here

//Show the main panel again
MainPanel.Visible = true;
ImagePanel.Visible = false;
}

So, the loading panel is shown correctly in the first place, but the reverse
is never done.
Any ideas

TIA

Grant


You should definitely check out Rob Howard's stuff about lengthy processes!
Go to www.rob-howard.net and grab the slides and demos from the
Blackbelt TechEd 2004 presentation.

//Rutger
 

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

Similar Threads

Threading 9
Thread 1
Multi Threading 2
threading and session object 8
Forcing a Method to be executed on the Main Thread 2
Threading 8
AJAX Page Loading Failure on Some Browsers 2
timer/threading 10

Top