updating inactive form.text from a thread in c# -
i'm trying update form.text thread. thread need update form.text current time. code looks below
updatetext("my monitor (last updated " + datetime.now.tostring("hh:mm:ss tt") + ")", form1.activeform); and method below
void updatetext(string s, command c) { if (c.invokerequired) { this.begininvoke(new methodinvoker(() => updatetext(s, c))); } else { c.text = s; } } as long main application window active, code works. if application becomes inactive, error "object reference not set instance of object"
you calling form1.activeform.
activeform: form represents active form, or null if there no active form.
if form inactive, naturally null. utilize different reference form. if calling within form, utilize this.
c#
No comments:
Post a Comment