showing form while processing

G

Guest

I have form with progress bar ,when application begin processing and progress
bar moving if I minimized the form and try to restore it ,it is not showing
until the processing completed ,how can I enabled minimize, maximize moving
form while processing in underway?
 
B

Bob Powell [MVP]

B

Bob Powell [MVP]

I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Create a thread and do the processing in that thread, you then have the UI
thread to react as usual, to update the progressbar you have two options,
you can use a timer to update it, or if your process is interactive ( like
a loop ) you could send an event to the UI ( using Control.Invoke ) at the
start of each iteration, you could pass info regarding the status or for
example what file you are processing, etc

post back if you need some code, I should have some instances around here.


cheers,
 
G

Guest

I did the bother Approches as Bob Said and you also , but i do not know i
think i did something wrong first i tried to call Application.DoEvents();
also i built a Thread Class

class ThreadClass
{
public ThreadClass(string mydata....etc){//I initialized my data}
public void Process(){//Do my work}
}

in main form function=> didi
ThreadClass oclass = new ThreadClass(pass params)
Thread oTh = new Thread(new ThreadStart(oclass.Process));
oTh.Start();
oTh.Join();

but still can not move,maximize the form???any suggestion
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

If you are using a thread you have no need to call Application.DoEvents.

First of all, you HAVE to remove the call to Join() it will block the UI
thread

Now a silly question: How do you increment the progressbar?
I think you have two options:
1- use a timer in the UI thread right after you create your now thread and
before.
2- fire an event from the worker thread as I suggested before.


cheers,
 
G

Guest

ok what should i do to make thread working other thank Join()

I increment the progress bar using PerformStep()
first i set the value as the number of file will be processed, then do call
PerformStep
 
I

Ignacio Machin \( .NET/ C# MVP \)

Raed Sawalha said:
ok what should i do to make thread working other thank Join()

It will be scheduled to start as soon as you call Thread.Start()
I increment the progress bar using PerformStep()
first i set the value as the number of file will be processed, then do
call
PerformStep

In this case you should fire an event from the thread each time a new file
is going to be processed. Let me dig around and see if I have an example
that does exactly that. you could also search in google this has been
answered before



cheers,
 
S

Sylwia Lubaczuk

Hi!

I have had the same problem to you, Read. Thanks all who gave here all
the clues. I thought that you, Read, possibly would like to see see the
solution i did thanks to these clues.
Here is my code (to make it more clear I removed not very important
code):


private void button1_Click(object sender, System.EventArgs e)
{

System.Threading.Thread newThread =
new System.Threading.Thread(new
System.Threading.ThreadStart(this.CreateBitmap));
newThread.Start();

}

private void CreateBitmap()
{

pBar.Minimum = 1;
pBar.Maximum = bmp.Height;
pBar.Value = 1;
pBar.Step = 1;
int y;
double percent ;

for(y=0; y < bmp.Height;y++)
{
// do your work
pBar.PerformStep();
percent = (((y*1.00)/pBar.Maximum)*100);
this.label1.Text = "Completed: " + Math.Ceiling(percent).ToString()
+ " %";

}
}

Cheers!
 

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