Hi
I'm developing a windows based c# application.
How do I update the UI with progress bar while Business Layer in process
where my BL is in a seprate Machine in the same network.
I tried by placing a thread to update the progress bar and at the same time BL function will also execute. But this doesn't seems to be working properly.
can any one sugest any methodolgies for this
Regards
Karthik

updating the UI with progress bar while Business Layer in process
BlakeC
And what does not work correctly Sample code
Remember one thing that the ProgressBar runs in the context of the Main Form and you cannot make changes to it directly from another thread. You need to make changes to it through delegates to ensure it's updated in the right thread context.
hisham_abu
Sorry I misunderstood your scenario.
IMO, the problem doesn't lie in the client. I guess the Business Layer must have an internal counter which acts like a countdown to when the operation ends. You could either expose an event that occurs everytime the value of the internal counter changes. Or you could just expose the internal counter, and create a thread in your client and use that internal counter's value to move the progressbar...
Hope that made sense...
cheers,
Paul June A. Domag
Marin Millar
following is my code for UI
MyUI.cs
-------
private bool IsBusinessEnds = false;
private void ProgressBarInc()
{
while(true)
{
//the value of the complexData is updated in BL. If it got updated I assume that BL job is finished and I make my progress bar to its max value.
if ( this.complexData.Lenght > 0
{
this.fileGenerationprogressBar.Value = 1000;
break;
}
else
{
this.fileGenerationprogressBar.Value += 1;
}
}
}< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
private
void OkButton_Click(object sender, System.EventArgs e){
Thread prog = new Thread(new System.Threading.ThreadStart(ProgressBarInc));
prog.Start();
//this is the call to the controller where in turn it will call the BL method which is done by remoting.
}
this.accountController.GenerateReminderFile(ref this.accountDataSet, ref this.complexData);
This method of doing is not sync up properly with progress bar.
And the progress bar is not updating properly.
how can I make changes to it through delegates
and how will I know whether BL method ends
and I can't use database for counters.
GaryM
I guess you should lookup on Socket Class. So that your two processes (.exe's) could communicate over the network...
cheers,
Paul June A. Domag
amerigo5
I belive that this can not be achived by using Threads and can be solved only by Call back functions thru Events & Delegate. I'm trying that way and once I got the solution I'll post it.
stift2
Hi Paul< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for the reply.
I'm not having 2 exe.
I'm having a exe (that is the client) the UI and one DLL which is the Business Layer resides in a different machine. My code would look like:
MyUI.cs
-------
BLClass1 blc = new BLClass1();
blc.SomeTimeTakingOperation();
since the execution control will be in SomeTimeTakingOperation() simultaneously I'm not able to update my MYUI.cs. I can only update the progress bar only after executing blc.SomeTimeTakingOperation(); or before this call.
So, Instead I tried by having a separate Thread and I'll update the UI's progress bar there and simultaneously BL method will execute. but this doesn't work.
can you please tell me how can I solve this by Socket class
gilb12
Gosatu
Uhmm, it "didn't work" because OK, here it is... and yes, it works... TWO different ways! Take your pick!
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BL bl = new BL();
// This works ONLY because of the Thread.Sleep() call within BL.Go().
bl.Go(this);
// This is the better way, (it doesn't require the Thread.Sleep() call)
// although you also have to manage shutting
// the thread down while it's in the middle of processing.
Thread thread = new Thread(new ParameterizedThreadStart(bl.Go));
thread.Start(this);
}
public void UpdateProgress(int progress)
{
// Invoke is required if UpdateProgress was called from a separate thread.
if (InvokeRequired)
Invoke( (MethodInvoker) delegate () { progressBar1.Value = progress; });
else
progressBar1.Value = progress;
}
}
public class BL
{
public void Go(Object param1)
{
Form1 form = (Form1)param1;
for (int i = 0; i < 100; i++)
{
form.UpdateProgress(i);
Thread.Sleep(10);
}
}
}
Kryten
Sri Harsha
presently I'm having a seprate Thread for updating the progress bar, and not for the BL. So, you r saying me to create a seprate Thread for BL and not for the UI.
Is it Right
So I'll call my BL method into a Thread is it right