469,282 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Best way to fire event

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
6 19006
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
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
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
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
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
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.

Similar topics

2 posts views Thread by Kevin Ly | last post: by
2 posts views Thread by Sam Miller | last post: by
2 posts views Thread by Ofer | last post: by
6 posts views Thread by Shimon Sim | last post: by
5 posts views Thread by Verde | last post: by
4 posts views Thread by Ty Salistean | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.