Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Caching objects between forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Sokolnicki - 02 Feb 2007 00:36 GMT
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.
Patrick Steele - 02 Feb 2007 01:20 GMT
> I'm trying to cache a user object and gain access to it from a mutlipe
> forms.
[quoted text clipped - 9 lines]
>
> 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.

Signature

Patrick Steele
http://weblogs.asp.net/psteele

Brian Sokolnicki - 02 Feb 2007 03:15 GMT
Thanks, sounds like it should work.

>> I'm trying to cache a user object and gain access to it from a mutlipe
>> forms.
[quoted text clipped - 29 lines]
> all other forms can access "MainForm.CurrentUser" to retrieve the one
> user object.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.