473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 19254
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.