So I'm creating a simple messaging application using entity framework, c#, and Azure. Here is my schema.
public class UserContext : DbContext {
public UserContext() : base("name=Official") {
}
public DbSet<User> Users { get; set; }
public DbSet<Message> Messages { get; set; }
}
public class User {
[Key]
public string username { get; set; }
public string password { get; set; }
//public int test { get; set; }
public virtual ICollection<User> friends { get; set; }
public virtual ICollection<Message> SentMessages { get; set; }
public virtual ICollection<Message> ReceivedMessages { get; set; }
public static implicit operator User(bool v) {
throw new NotImplementedException();
}
public override string ToString() {
return username;
}
}
public class Message {
[Key]
public int ID { get; set; }
public virtual User sender { get; set; }
public virtual User recipient { get; set; }
public virtual Group group { get; set; }
public string content { get; set; }
public int TimeSent { get; set; }
}
public class Group {
[Key]
public int ID { get; set; }
public virtual ICollection<User> members { get; set; }
public virtual ICollection<Message> messages { get; set; }
}
My DB is declared in a UniversalStuff class once and I access it everywhere throughout the program.
public static UserContext db = new UserContext();
So I have a Conversations Form that is basically the main screen and it looks like this:
The problem I'm having is finding a way to update the program so that new messages that were sent to you while you have the program running to show up in the textbox on the right.
I "solved" it by disposing and recreating the DB object everytime the user changes the selected item in the listbox on the right (or even click in the whitespace). Obviously this isn't the best way to do this, and now i want to implement system tray notifications so if the program is minimized to the task bar you can see if you received a new notification.
Now, on to the question: What would be the best way to have new messages pop in without the user having to do anything?