Re: An object reference is required for the non-static field, method, or property message
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Wed, 18 Jun 2008 07:17:23 -0700 (PDT)
On Jun 18, 5:58 pm, "Dave" <d...@xxxxx> wrote:
The problem is with my listbox on the form.
I am trying to run 2 threads simulataneously an update two different listbox
controls but my functions are complaining that the listbox doesn't have an
object reference, my listboxes were created by the ide and drawn on the
form at design time.
How can I give my listbox a reference?
Very simple: make methods you use as thread entry points (in your
case, AddItems1 and AddItems2) non-static.
In addition to that, you cannot call (most) methods and properties on
Windows Forms controls from any thread other than the one which had
created them. In your case, trying to add an item to the ListBox from
another thread will result in an exception. You can work around this
by using Control.Invoke and Control.BeginInvoke as needed - MSDN has
more details and examples, as usual.
.
- References:
- Prev by Date: Re: What is that question (?) sign after a type declaration?
- Next by Date: Re: Analyze .SQL, .CSV and .XLS-files
- Previous by thread: An object reference is required for the non-static field, method, or property message
- Next by thread: RE: An object reference is required for the non-static field, method,
- Index(es):
Relevant Pages
|
Loading