Refreshing ListBox items every few seconds C# -


list<string> listbox = new list<string>();  private void form1_load(object sender, eventargs e) {     process[] processes = process.getprocesses();      foreach (var proc in processes)     {         if (!string.isnullorempty(proc.processname))             listbox.add(proc.processname);     }     listbox1.datasource = listbox; } 

while using code, listbox (listbox1) shows of running processes, can adjust of code/add make refresh listbox every 5 seconds, since shows programs open when application opened, , if application closed/opened while opened, won't added listbox, hence why want refresh every 5 seconds or so.

you can use timer this:

private timer m_timer;  private void form1_load(object sender, eventargs e) {     refreshprocesses();      m_timer = new timer();      m_timer.interval = 5000;     m_timer.tick += timer_tick;     m_timer.start(); }  void timer_tick(object sender, eventargs e) {     refreshprocesses(); }  private void refreshprocesses() {     list<string> listbox = new list<string>();      process[] processes = process.getprocesses();      foreach (var proc in processes)     {         if (!string.isnullorempty(proc.processname))             listbox.add(proc.processname);     }     listbox1.datasource = listbox; } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -