Hi Steve
I ran into a few problems with the InvokeRequired, which ended up
producing similar cross thread errors I think, I was doing something
wrong anyways :-). I went with BackgroundWorker in the end and quickly
had things working as required.
Steve ;)
http://www.pretty-vacant.co.uk
On Tue, 6 Jun 2006 11:05:04 -0700, "Steve" <skle@skle.com> wrote:
[color=blue]
>I forgot to mention why I like this. Rather than put the Invoke logic in
>each location that might make a call to the UI methods, I only need to add
>it to one place, the UI method. So I could have 20 different classes,
>services, events etc all hitting that UI method and it will be protected.
>
>
>"Steve" <nospam@here.com> wrote in message
>news:n1cb821i694mdh8p5jndskrnt0110lsjrr@4ax.com.. .[color=green]
>> On Tue, 6 Jun 2006 10:49:47 +0100, "Daniel" <DanielV@vestryonline.com>
>> wrote:
>>[color=darkred]
>>>Hi guys
>>>
>>>I have a form with my gui on, just some list boxes.
>>>
>>>And a class that handles incoming data.
>>>
>>>i want to, on receiving data, update my gui.
>>>
>>>However even though i have an instance created in my class handling the
>>>receiving data of the gui form if i try and update the gui directly i get
>>>a
>>>cross thread error, trying to access the form listbox from a thread other
>>>that the one it was created on.
>>>
>>>its because the method that called the gui update method is asynchronous.
>>>
>>>How do i get round this, i have tried using events and delegates getting
>>>the
>>>class to, on receving data, fire an event and then hook that event to the
>>>gui so it updates on the event firing but this still causes the same
>>>error.
>>>
>>>This must be possible right?
>>>[/color]
>>
>>
>> Use the BackgroundWorker object in System.ComponentModel. There is a
>> pretty good example here
>>
>>
http://msdn2.microsoft.com/en-us/sys...undworker.aspx
>>
>> BackgroundWorker is very easy to use.
>>
>> The link above contains detailed info and the example (c#/vb/cpp) is
>> clear, I used it as a base for my own asynchronous functions when I
>> ran into the same problem as yourself, so I know it works. If you need
>> a hand let me know. Just to say, I tried several methods before
>> deciding on using BackgroundWorker, it is certainly suitable for the
>> task.
>>
>> chers
>>
>> Steve
>>
>>
http://www.pretty-vacant.co.uk[/color]
>[/color]