Click here to Skip to main content
15,888,527 members
Home / Discussions / C#
   

C#

 
Questiondelete a file automatically Pin
lawrenceinba12-Mar-10 21:53
lawrenceinba12-Mar-10 21:53 
AnswerRe: delete a file automatically Pin
Anubhava Dimri12-Mar-10 22:12
Anubhava Dimri12-Mar-10 22:12 
AnswerRe: delete a file automatically Pin
Abhinav S12-Mar-10 22:14
Abhinav S12-Mar-10 22:14 
GeneralRe: delete a file automatically Pin
lawrenceinba12-Mar-10 22:26
lawrenceinba12-Mar-10 22:26 
GeneralRe: delete a file automatically Pin
Abhinav S12-Mar-10 22:46
Abhinav S12-Mar-10 22:46 
AnswerRe: delete a file automatically Pin
OriginalGriff12-Mar-10 22:22
mveOriginalGriff12-Mar-10 22:22 
AnswerRe: delete a file automatically Pin
#realJSOP13-Mar-10 0:50
mve#realJSOP13-Mar-10 0:50 
QuestionSingleton problems Pin
nordsluttning12-Mar-10 21:44
nordsluttning12-Mar-10 21:44 
Hi there!

I'm building a client/server-app with .Net remoting. I want the server to cache data for logged in users.

The code which wont function the way I want looks like this:
public sealed class Notifier
{
    static Notifier instance = null;
    static readonly object padlock = new object();
    System.Timers.Timer timer = new System.Timers.Timer(10000);
    static HashSet<UserInfo> users = new HashSet<UserInfo>();

    Notifier()
    {
       SetUpTimer();
    }

    public static Notifier Instance
    {
        get
        {
            lock (padlock)
            (
                if (instance == null)
                {
                   instance = new Notifier();
                }
                   return instance;
                }
            }
        }
    }
    
    public void ConnectUser(UserInfo user)
    {
        foreach (UserInfo info in users)
        {
            if ((info.UserName == user.UserName))
                return;
        }
        users.Add(user);
    }

    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (users.Count == 0)
            return;
        timer.Enabled = false;
     
        //A lot of code...
   
        timer.Enabled = true;
    }
}


When adding a UserInfo with the ConnectUser() method the UserInfo object will be added to the users HashSet. However, when I try to access it in timer_elapsed the HashSet is empty, even though I've added 1000 UserData in the Connect method. I've tried make the HashSet staic, non-static but the problem remains.

ANy ideas?

Thomas
AnswerRe: Singleton problems Pin
Abhinav S12-Mar-10 22:07
Abhinav S12-Mar-10 22:07 
GeneralRe: Singleton problems Pin
nordsluttning12-Mar-10 22:22
nordsluttning12-Mar-10 22:22 
AnswerRe: Singleton problems Pin
Luc Pattyn13-Mar-10 2:46
sitebuilderLuc Pattyn13-Mar-10 2:46 
GeneralRe: Singleton problems Pin
nordsluttning13-Mar-10 4:21
nordsluttning13-Mar-10 4:21 
QuestionHorizontal scrolling in list box Pin
Reza Shojaee12-Mar-10 21:29
Reza Shojaee12-Mar-10 21:29 
AnswerMessage Removed Pin
12-Mar-10 21:32
Anubhava Dimri12-Mar-10 21:32 
GeneralRe: Horizontal scrolling in list box Pin
OriginalGriff12-Mar-10 22:09
mveOriginalGriff12-Mar-10 22:09 
AnswerRe: Horizontal scrolling in list box Pin
OriginalGriff12-Mar-10 22:09
mveOriginalGriff12-Mar-10 22:09 
QuestionHow organize privilege levels in my client-server database (C#) [modified] Pin
Xgener12-Mar-10 20:26
Xgener12-Mar-10 20:26 
AnswerRe: How organize privilege levels in my client-server database (C#) Pin
#realJSOP13-Mar-10 0:52
mve#realJSOP13-Mar-10 0:52 
QuestionDataTemplate in ListBox Not working Pin
Anu_Bala12-Mar-10 17:24
Anu_Bala12-Mar-10 17:24 
AnswerRe: DataTemplate in ListBox Not working Pin
Abhinav S12-Mar-10 19:59
Abhinav S12-Mar-10 19:59 
GeneralRe: DataTemplate in ListBox Not working Pin
#realJSOP13-Mar-10 0:54
mve#realJSOP13-Mar-10 0:54 
QuestionRunning Multiple Versions of Crystal Reports in WinApp. Pin
DotNetMan12-Mar-10 17:07
DotNetMan12-Mar-10 17:07 
AnswerRe: Running Multiple Versions of Crystal Reports in WinApp. Pin
DotNetMan13-Mar-10 1:53
DotNetMan13-Mar-10 1:53 
QuestionResponding to Web Browser generated MessageBox Pin
Lilith.C12-Mar-10 14:47
Lilith.C12-Mar-10 14:47 
AnswerRe: Responding to Web Browser generated MessageBox Pin
#realJSOP13-Mar-10 0:59
mve#realJSOP13-Mar-10 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.