Best way to fire event

S

sjoshi

I have a derived class OraBackup which has a method that calls stored
procedure on Oracledb to get status of backup job.

Now the base class publishes an event like this:

public delegate void PercentEventHandler(object sender,
JobCompletedEventArgs e);
public event PercentEventHandler PercentCompleted;

And fires it:
protected void OnPercentCompletion(JobCompletedEventArgs e)
{
if (PercentCompleted != null)
PercentCompleted(this, e);
}

to report progress to UI.

Since I have to keep calling the method in OraBackup to check the
progress, I was wondering what would be the best way to do this in the
derived OraBackup class:

public void CheckProgress()
{
string jobStatus;
int percent = _oraGateway.GetProgress(jobName, out jobStatus)
//Fire event
OnPercentCompletion(new JobCompletedEventArgs(percent);

//I need to keep firing until the jobStatus is "COMPLETED" or
"STOPPED";
}

thanks
Sunit
 
G

Guest

Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
 
D

Daniel

So your answer is to say, fire your event this way and lose your % update
functionality?

His question was best way to fire an event in that scenario. So the answer
required should address the % issue, best way, and the event issue.

I agree an event should be raised when it's complete, but then how can he
also retrieve progress status?

My opinion would be an internal var in the class that is receiving the
information. Use that var to update your progress bar on a new thread to
keep your UI from locking. The have the progress bar trigger an event to say
when it is complete.

That addresses the % requirement and the event firing.
 
G

Guest

What I mean is, create a separate event to signal completion (or "Stopped").
There can be a boolean IsComplete field that would be set to true, and the
PercentComplete event would check this before it continues to send out
percent messages to subscribers.
All he needs is some means to tell the called when to stop "polling" because
the backup job is REALLY REALLY DONE.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
 
D

Daniel

So your still firing an event to subscribers of % change if it hasnt
completed:

"PercentComplete event would check this before it continues to send out
percent messages to subscribers."

Once it his 100% it knows its done.
 

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