Caching objects between forms

  • Thread starter Thread starter Brian Sokolnicki
  • Start date Start date
B

Brian Sokolnicki

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.
 
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.
 
Thanks, sounds like it should work.

Patrick Steele said:
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.
 
Back
Top