So I have multiple threads running in vb.net. I need to know, how does one add to a listbox that was "created in a different thread"? I can't seem to get past this error!
Exact Error:
System.InvalidOperationException occurred
HResult=0x80131509
Message=Cross-thread operation not valid: Control 'ListBox2' accessed from a thread other than the thread it was created on.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.ListBox.NativeAdd(Object item)
at System.Windows.Forms.ListBox.ObjectCollection.AddInternal(Object item)
at System.Windows.Forms.ListBox.ObjectCollection.Add(Object item)
at SuperBC_Check_Pro.Form1.IncluBC(String username, String membershipType) in C:\Users\Owner\documents\visual studio 2017\Projects\SuperBC-Check Pro\SuperBC-Check Pro\Form1.vb:line 64
at SuperBC_Check_Pro.Form1.CheckBCMembership() in C:\Users\Owner\documents\visual studio 2017\Projects\SuperBC-Check Pro\SuperBC-Check Pro\Form1.vb:line 92
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
What do you guys suggest I go about fixing such an error?