threading

  • Thread starter Thread starter Grant Merwitz
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
Back
Top