c# - Updating UI controls from another class -
i using signalr implement notification system exchange information between application instances. have following hub class:
[hubname("openhub")] public class openhub:hub { public void determinelength(string message) { clients.all.recievenewinfo(newmessage); //how use following line? //concerning form1 loaded @ application startup //and should not create new instance //form1.lstmessages.add(newmessage); } }
yet, have update ui controls including label , listbox log whatever new information has arrived. besides defining class in form's code, how can update form object show these new information when have hub defined in different class?
you can use public static property in program
class or form1
class hold reference it.
for example in program
before using application.run(new form1());
you can this:
public static form1 mainform { get; set; }
and in main()
mainform = new form1(); application.run(mainform);
from hub can access form now:
[hubname("openhub")] public class openhub:hub { public void determinelength(string message) { clients.all.recievenewinfo(newmessage); program.mainform.lstmessages.add(newmessage); } }
of course, lstmessages
should public. or better expose in form public method communicate it.
Comments
Post a Comment