472,985 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

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 19235
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Ly | last post by:
Consider the test case below. The onmouseout event does NOT fire when my mouse/cusor is moved off the left side of the browser. It does if it is moved off the top, bottom, and the right side that...
9
by: HJ | last post by:
Hi all, I notice that the Form_Dirty event does not fire in Access 2002 (SP-1) when the first character is typed into a new record. In previous versions of Access it does fire. For existing...
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
2
by: Ofer | last post by:
I finally learned that DataGrid1.EditItemIndex = {row I want} -1 DataGrid1.DataBind() will make that row get to edit mode. I am stiil looking for ways to programticaly do other things: 1) show...
6
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
5
by: Verde | last post by:
This is admittedly an apparently odd request... but please indulge me if you don't mind: Suppose I have two <asp:Button.../> on a page (Button1 and Button2). User clicks Button1 and triggers a...
4
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
by: TH | last post by:
Hi there What's the best way for a popup to cause an event to fire in the opener? I've got a popup which currently returns a value to the opener by setting a hidden input in the opener: ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.