Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1)with timer i am loading a form showing users online
2)while the timer loading the users online it will checks any messages from the users if so it will open a new window form.

Issue:
if a form is opened already for an user(A) again its opening a new form for the same user(A).
My Code:
C#
private void timer1_Tick(object sender, EventArgs e)
        {
            displaying users online
             {
               any messages from the user
               if the above statement is true 
               {
                 //open a new chat form
               }
             }
        }

How to resolve the issue to stop opening multiple forms for single user.
Posted
Updated 4-Jun-13 3:10am
v2

you have a main form inside which multiple chat forms are loading...
now,in that mainform,
take page level variable
C#
List<int> openedchats = new List<int>();  </int></int>

now, when open form on timer
C#
if (!openedchats.Contains(userId))
{ 
    openedchats.add(userId);

    frmchat c = new frmchat();
    c.Tag = userId;
    c.Parent = this;
    c.show();
}
else
{
    //nothing to do
}

Add method... in parent form
C#
public void RemovefromOpenedchats(int userid)
{
     openedchats.Remove(userId);	
}


and in frmchat form
in form_closing event
C#
(MainForm)this.Parent.RemovefromOpenedchats((int)this.Tag);


Happy Coding!
:)
 
Share this answer
 
Comments
riodejenris14 4-Jun-13 11:27am    
thnx aarti!!!!
Aarti Meswania 4-Jun-13 13:10pm    
Welcome!
Glad to help you! :)
It's not very clear what you mean exactly. But simply have a reference to the form and check it isn't null or if(form.Visible). You can also cancel the timer when opening a form outside of the timer.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900