PC Review


Reply
Thread Tools Rate Thread

Caching objects between forms

 
 
Brian Sokolnicki
Guest
Posts: n/a
 
      2nd Feb 2007
I'm trying to cache a user object and gain access to it from a mutlipe
forms.

I have created a base class that all forms will inherit from. In this base
class, I have a propery to a User class which I want to cache and reuse on
all other forms so that I don't need to retrieve the user data from every
screen.

For every form that is open, there is a OnLoad override in the base class
that will call the getuser method in the user class and this will check to
see if there's a cached object or not.

Is this possible?

I have most of the logic written but can't figure out how to accomplish
this.

Thanks.


 
Reply With Quote
 
 
 
 
Patrick Steele
Guest
Posts: n/a
 
      2nd Feb 2007
In article <(E-Mail Removed)>, (E-Mail Removed)
says...
> I'm trying to cache a user object and gain access to it from a mutlipe
> forms.
>
> I have created a base class that all forms will inherit from. In this base
> class, I have a propery to a User class which I want to cache and reuse on
> all other forms so that I don't need to retrieve the user data from every
> screen.
>
> For every form that is open, there is a OnLoad override in the base class
> that will call the getuser method in the user class and this will check to
> see if there's a cached object or not.
>
> Is this possible?


Create a static (Shared in VB.NET) reference to your user object on your
main form. Something like this (C#):

public class MainForm : Form
{
private static UserObject _currentUser;

public static UserObject CurrentUser
{
get { return _currentUser; }
}
}

Somewhere in "MainForm", the user object is initialized and loaded. Now
all other forms can access "MainForm.CurrentUser" to retrieve the one
user object.


--
Patrick Steele
http://weblogs.asp.net/psteele
 
Reply With Quote
 
Brian Sokolnicki
Guest
Posts: n/a
 
      2nd Feb 2007
Thanks, sounds like it should work.

"Patrick Steele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>, (E-Mail Removed)
> says...
>> I'm trying to cache a user object and gain access to it from a mutlipe
>> forms.
>>
>> I have created a base class that all forms will inherit from. In this
>> base
>> class, I have a propery to a User class which I want to cache and reuse
>> on
>> all other forms so that I don't need to retrieve the user data from every
>> screen.
>>
>> For every form that is open, there is a OnLoad override in the base class
>> that will call the getuser method in the user class and this will check
>> to
>> see if there's a cached object or not.
>>
>> Is this possible?

>
> Create a static (Shared in VB.NET) reference to your user object on your
> main form. Something like this (C#):
>
> public class MainForm : Form
> {
> private static UserObject _currentUser;
>
> public static UserObject CurrentUser
> {
> get { return _currentUser; }
> }
> }
>
> Somewhere in "MainForm", the user object is initialized and loaded. Now
> all other forms can access "MainForm.CurrentUser" to retrieve the one
> user object.
>
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ Caching Objects Craig Wagner Microsoft Dot NET Framework 4 7th Apr 2008 03:56 PM
Caching business objects? Showjumper Microsoft ASP .NET 5 23rd Aug 2007 01:00 PM
Caching objects Joel Barsotti Microsoft ASP .NET 2 28th Jan 2006 12:16 AM
caching objects and data Microsoft Dot NET Framework 5 29th Jun 2005 11:34 PM
Caching Objects matthias s. Microsoft ASP .NET 2 9th Jun 2005 06:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:59 PM.