By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,769 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,769 IT Pros & Developers. It's quick & easy.

Best way to fire event

P: n/a
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

Jan 29 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:
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

Jan 29 '07 #2

P: n/a
He is passing a % val, presumably to update a progress bar....which is why.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FB**********************************@microsof t.com...
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:
>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


Jan 29 '07 #3

P: n/a
Yes I am aware of what he is doing. That's the whole purpose of events. The
subscriber gets the callback when the event is raised. So instead of a "what
percent is it event", he really needs a "is it complete event".
Peter

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


"Daniel" wrote:
He is passing a % val, presumably to update a progress bar....which is why.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FB**********************************@microsof t.com...
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:
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



Jan 30 '07 #4

P: n/a
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.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:E2**********************************@microsof t.com...
Yes I am aware of what he is doing. That's the whole purpose of events.
The
subscriber gets the callback when the event is raised. So instead of a
"what
percent is it event", he really needs a "is it complete event".
Peter

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


"Daniel" wrote:
>He is passing a % val, presumably to update a progress bar....which is
why.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FB**********************************@microsof t.com...
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:

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




Jan 30 '07 #5

P: n/a
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


"Daniel" wrote:
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.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:E2**********************************@microsof t.com...
Yes I am aware of what he is doing. That's the whole purpose of events.
The
subscriber gets the callback when the event is raised. So instead of a
"what
percent is it event", he really needs a "is it complete event".
Peter

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


"Daniel" wrote:
He is passing a % val, presumably to update a progress bar....which is
why.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FB**********************************@microsof t.com...
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:

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




Jan 30 '07 #6

P: n/a
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.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:EC**********************************@microsof t.com...
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


"Daniel" wrote:
>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.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:E2**********************************@microsof t.com...
Yes I am aware of what he is doing. That's the whole purpose of events.
The
subscriber gets the callback when the event is raised. So instead of a
"what
percent is it event", he really needs a "is it complete event".
Peter

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


"Daniel" wrote:

He is passing a % val, presumably to update a progress bar....which is
why.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:FB**********************************@microsof t.com...
Why can't you just add a JobStatus event That returns
CompletedStatus.COMPLETE or CompletedStatus.STOPPED ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"sjoshi" wrote:

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





Jan 30 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.