473,790 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Event for DataSet Read?


I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a
DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of
the rows in the DataTable. I think I want to make a custom event but
I don't know where/how to get started. Help?

Thanks.

Nov 15 '05 #1
10 1533

"localhost" <pr*******@coho rt.ces> wrote in message
news:cl******** *************** *********@4ax.c om...

I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a
DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of
the rows in the DataTable. I think I want to make a custom event but
I don't know where/how to get started. Help?


If it is up to me, I would hide the dataset property, and make it accessible
only from my own defined methods...

for example:

public class CustomDataSet
{
private System.Data.Dat aset _myDataset;
public CustomDataSet()
{
myDataSet = new System.Data.Dat aSet( );
}

// One example for a public function might be:
public bool FillDataSet(Sys tem.Data.DataAd apter adapter)
{
// Do whatever you wish here..
// ....
return false;
}

public DataRow GetRow(int index)
{
DataRow ret = _myDataset.Tabl es[ 0 ].Rows[ index ];
// Do whatever you wish here, for example:
_myDataset.Tabl es[ 0 ].Rows.Clear( );
return ret;
}
}

Or you might find it more robust to define class indexers for getting rows
at certain indecies, while you will still be able to control access to your
hidden dataset.


Nov 15 '05 #2

That is not quite what I am talking about. Thanks for the response,
though.

I'm not doing anything with DataAdapters or anything like that.

What I need to accomplish is a way for the private DataSet, which
exists as a property on the static class (accessed through a public
"get"), to be recreated each time a caller gets an instance of the
class so each caller gets a new DataSet.

Thanks.

On Wed, 25 Feb 2004 23:09:43 +0200, "hOSAM"
<bk************ *********@yahoo .com> wrote:

"localhost" <pr*******@coho rt.ces> wrote in message
news:cl******* *************** **********@4ax. com...

I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of the rows in the DataTable. I think I want to make a custom event but I don't know where/how to get started. Help?
If it is up to me, I would hide the dataset property, and make it

accessibleonly from my own defined methods...

for example:

public class CustomDataSet
{
private System.Data.Dat aset _myDataset;
public CustomDataSet()
{
myDataSet = new System.Data.Dat aSet( );
}

// One example for a public function might be:
public bool FillDataSet(Sys tem.Data.DataAd apter adapter)
{
// Do whatever you wish here..
// ....
return false;
}

public DataRow GetRow(int index)
{
DataRow ret = _myDataset.Tabl es[ 0 ].Rows[ index ];
// Do whatever you wish here, for example:
_myDataset.Tabl es[ 0 ].Rows.Clear( );
return ret;
}
}

Or you might find it more robust to define class indexers for getting rowsat certain indecies, while you will still be able to control access to yourhidden dataset.


Nov 15 '05 #3

Hi localhost,

If so, can't you create a new dataset in your property's "get" method? Like
this:

public class yourclass
{
private DataSet _ds;

public DataSet dataset
{
get
{
if(something you want)
{
DataSet ds=new DataSet();
//do something to your new dataset
return ds;
}

}
set
{
_ds=value;
}
}
}

In this solution, your public "dataset" property will create a new dataset
when some condition meets.

=============== =============== ===========
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4

The problem is that the class is instanced only once (Singleton). If
I just use a classic get/set, then a client could populate the DataSet
property and then crash, and then the next client could populate the
DataSet property and get both client DataSet info.

What I need to do is make sure the DataSet is truly new each time a
client instances the object.

I think I need to rework this into two classes, an event raiser and an
event consumer, so each time a client connects an event is raised and
the DataSet property is set to a new one.
How can I do that?

On Fri, 27 Feb 2004 09:04:21 GMT, v-*****@online.mi crosoft.com
(""Jeffrey Tan[MSFT]"") wrote:

Hi localhost,

If so, can't you create a new dataset in your property's "get" method? Likethis:

public class yourclass
{
private DataSet _ds;

public DataSet dataset
{
get
{
if(something you want)
{
DataSet ds=new DataSet();
//do something to your new dataset
return ds;
}

}
set
{
_ds=value;
}
}
}

In this solution, your public "dataset" property will create a new datasetwhen some condition meets.

============== =============== ============
Thank you for your patience and cooperation. If you have any questions orconcerns, please feel free to post it in the group. I am standing by to beof assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no

rights.

Nov 15 '05 #5

Hi localhost,

Thanks very much for your feedback.

Sorry, I think I did not fully understand your point.

Actually, if you use the sample code I provide, whenever you visit the
dataset property, a new dataset will return. Event you use the same class
instance, each time you invoke this property, a new dataset will return, so
I can not find any problem.

Can you show me the problem?

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6
/*

Below is a stripped-down version of the class.
It is named singlestonstuff .cs

The usage pattern is:
1. Callers try to get the single instance of the class.
2. The class sets its DataSet property to new.
3. Caller makes multiple method calls to add info to the
DataSet property.
4. Caller requests the entire populated DataSet.
5. Caller disconnects.

I need to guarantee that every time (1) happens,
(2) also happens. Right now, (1) can happen and then
the caller can exit (from a crash, etc), and then when
a new caller appears they will get the same DataSet
populated by a earlier caller.

Is it possible for you to show how a delegate (with
events) can be hooked into this so the DataSet is
always given fresh for each caller?
Right now my workaround is for each caller to
get an instance of the class and then touch the
DsClear() method. I want DsClear to happen
internally with this class instead - can you
please show how this can be done with an event?

This compiles with
"csc /target:library singletonstuff. cs"

Thanks.

*/
using System;
using System.Data;
using System.Collecti ons;

public sealed class DataSetStuffer
{
// Thread-safe usage without using locks
static readonly DataSetStuffer dssInstance =
new DataSetStuffer( );

// Explicit static constructor tells compiler
// not to mark type as BeforeFieldInit
// Thanks to Jon at http://www.yoda.arachsys.com/
static DataSetStuffer( )
{
}
DataSetStuffer( )
{
PrepDs();
}
public static DataSetStuffer GetInstance()
{
return dssInstance;
}
private DataSet _dataSet = new DataSet();
public DataSet dataSet
{
get
{
DataSet outSet = _dataSet.Copy() ;
DsClear();
return outSet;
}
}
private void PrepDs()
{
string callerName =
new System.Diagnost ics.StackFrame( 3).GetMethod(). Name;
DataTable dataTable = new DataTable();
dataTable.Colum ns.Add( "Something" ,
typeof(System.S tring) );
_dataSet.Tables .Add( dataTable );
}
public void TakeInfo( string clientInfo )
{
_dataSet.Tables[0].Rows.Add
( new Object[] { clientInfo } );
}
public void DsClear()
{
_dataSet = new DataSet();
PrepDs();
}
}

Nov 15 '05 #7
Hi localhost,

Thanks very much for your feedback.

I have seen your code, also have seen your problem.

I think your problem may only occur under multithread environment, at the
sequence below:

Thread1: DataSet outSet = _dataSet.Copy() ;
Thread1: Collapse, or sleep etc..
Thread2: DataSet outSet = _dataSet.Copy() ;
Thread2: DsClear();
Thread2: return outSet;

Then, thread2 will get the same instance as thread1.

I think the problem is due to the 2 statements below did not executive as
an atom operation
DataSet outSet = _dataSet.Copy() ;
DsClear();

The solution is make these 2 statements into an atom operation to make
threads access this section synchronously.
In .Net, you can use System.Threadin g.Mutext class to do synchronization ,
like this:

private static Mutex mut = new Mutex();

private DataSet _dataSet = new DataSet();
public DataSet dataSet
{
get
{
mut.WaitOne();
DataSet outSet = _dataSet.Copy() ;
DsClear();
mut.ReleaseMute x();
return outSet;
}
}

=============== =============== =============== ==
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #8

That looks good. Yes, this stand-alone DLL will be used by ASP.NET
callers, so it must be fully thread safe and support multithreading.

Is try...finally functionality necessary inside the get?

Thanks.

On Wed, 03 Mar 2004 02:45:51 GMT, v-*****@online.mi crosoft.com
(""Jeffrey Tan[MSFT]"") wrote:
Hi localhost,

Thanks very much for your feedback.

I have seen your code, also have seen your problem.

I think your problem may only occur under multithread environment, at thesequence below:

Thread1: DataSet outSet = _dataSet.Copy() ;
Thread1: Collapse, or sleep etc..
Thread2: DataSet outSet = _dataSet.Copy() ;
Thread2: DsClear();
Thread2: return outSet;

Then, thread2 will get the same instance as thread1.

I think the problem is due to the 2 statements below did not executive asan atom operation
DataSet outSet = _dataSet.Copy() ;
DsClear();

The solution is make these 2 statements into an atom operation to makethreads access this section synchronously.
In .Net, you can use System.Threadin g.Mutext class to do synchronization ,like this:

private static Mutex mut = new Mutex();

private DataSet _dataSet = new DataSet();
public DataSet dataSet
{
get
{
mut.WaitOne();
DataSet outSet = _dataSet.Copy() ;
DsClear();
mut.ReleaseMute x();
return outSet;
}
}

============== =============== =============== ===
Thank you for your patience and cooperation. If you have any questions orconcerns, please feel free to post it in the group. I am standing by to beof assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no

rights.

Nov 15 '05 #9

Hi localhost,

Thanks very much for your feedback.

I am glad my reply makes sense to you.

Yes, use try...catch in the code is a good habit which enable robust code
in your application.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4093
by: T | last post by:
I have a web site i want to deploy using a VS.NEt set up project. I have no problems with that, that is fine and works no problem. But the web application uses a custom event log to log application messages. The asp.net application will not be running under an account with administrative permissions and so this will not be able to create the custom event log.
1
1388
by: Victor | last post by:
I am developing a windows service application that uses a custom event. the problem is that the service installer associates the service with application log during the installation process. Therefore, the custom log does not recieve messages from the event source. Below is code snipet ' check if log exists on this machine If Not EventLog.SourceExists("trkProcessMin") Then
3
4695
by: bruce | last post by:
Hello, I am trying to figure out how to use a class with a custom event as a wrapper for a subform so that I can automatically trigger things to happen on the parent form when the custom event is raised. I am new to custom events, so please bear with me... I have created a class module (clsMyEvent) as follows: Option Compare Database
5
3270
by: Simon Middlemiss | last post by:
I am writting a program to manage DTS packages which is based on the code example at the following link http:\\www.support.microsoft.com/?kbid=319985. I need to do things in a Windows Forms Application when various things occur in the package so I have written some custom events to reraise the events caught in the PackageEventsSink class. I also have a listview in details mode with several columns, my problem is that when I try and...
3
1837
by: bill | last post by:
I am using VS2005 to build a web form dynamically. I'm using AddHandler to connect a custom event handler to the TextChanged event of dynamically added textbox controls. Data entered in the dynamically added textbox controls is saved to a database in the custom event handler. The custom event handler fires when the page posts back. I have a menu control which causes a postback, and the custom event handler then fires if a textbox...
2
3743
by: T McDonald | last post by:
I've been having a problem writing to an event to the Application log. I believe the issue is caused by the fact that the source was previously both a custom log and the source. I deleted the log using EventLog.Delete(logname); I couldn't delete the source as it there was an error reporting that I couldn't delete the event source as it had the same name as the log. Once I deleted the log, the source appeared to not have any reference to...
2
1868
by: trialproduct2004 | last post by:
Hi all, I am having application in whihc i am inserting menuitem dynamically. When i add menuitem to mainmenu, i want to pass extra parameter to eventargs. So what i did is derived class from eventargs and created my own variable into this class. And then while setting eventhandler i am passing this custom event args. But this is not working.
6
1885
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as pressing a button or changing text in a textbox). It gets set up and on the user control on my web page I can see the event from intellisense. So it seems to be set up, but I am trying to get an easy example of how I would now use this event. ...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.