c# - Removing tabs programatically - Controls created on one thread cannot be parented to a control on a different thread -


i have app uses loop , adds tabs. here code.

textbox logtextbox = new textbox();                 logtextbox.name = "textbox1_" + string1234[0]; //string.format("logthread{0}", i);                 logtextbox.multiline = true;                 logtextbox.size = new system.drawing.size(587, 404);                 logtextbox.location = new system.drawing.point(8, 6);                 logtextbox.anchor = (anchorstyles.left | anchorstyles.bottom | anchorstyles.right | anchorstyles.top);                  string title = string1234[0];                 tabpage mytabpage = new tabpage(title);                 mytabpage.name = string.format("tabthread{0}", i);                   mytabpage.controls.add(logtextbox);                   tabcontrol1.tabpages.add(mytabpage);                    botthread = new thread(() => mainthread(string123, i));                 botthread.isbackground = true;                 botthread.name = string.format("123thread{0}", i);                  _threads.add(botthread);                 botthread.start(); 

this code works fine , adds tab text box , thread starts. when try end thread, delete textbox , remove tab error.

here code use

public void killthread(int index, int index1, string textname)          {              string id = string.format("taggerthread{0}", index);             foreach (thread thread in _threads)             {                 if (thread.name == id)                     thread.abort();             }              string id1 = string.format("tabthread{0}", index1);              foreach (tabpage tab in tabcontrol1.tabpages)             {                  if (tab.name == id1)                 {                     tab.controls.removebykey(textname);                     tabcontrol1.tabpages.removebykey(id1);                  }             } 

the program breaks , vs 12 give me error when debugging.

an unhandled exception of type 'system.argumentexception' occurred in system.windows.forms.dll

additional information: controls created on 1 thread cannot parented control on different thread. 

it hightlights line when break program, tabcontrol1.tabpages.add(mytabpage);

what can stop threads, remove tabs , controls. multi thread app track id , strings.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -