473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using EndInvoke From within an AsyncCallback?

I've been working on some samples that use BeginInvoke/EndInvoke. In one
example, I call BeginInvoke and pass it an AsyncCallback function pointer.
I was messing around with ReaderWriterLocks and noticed that if I did this,
it worked (please ignore the lack of try ... catch blocks, because I cut
down the code to be more brief - I have a try...catch surround the
AcquireWriterLock method):
----------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,null,null);

// Some other async operations can be done here

// Get the results of the delegate using EndInvoke. This will block
// execution of this thread until the delegate invoked completes
fprUIUpdate.EndInvoke(iasResult);
myLock.ReleaseWriterLock();
---------
But, if I do it this way, the WriterLock never gets cleared, even though the
statement gets executed in the AsyncCallback method:
---------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,new
AsyncCallback(MessageUpdatedCallBack),null);

// Some other async operations can be done here

public void MessageUpdatedCallBack(System.IAsyncResult Result)
{
// Get the results of the delegate using EndInvoke
fprUIUpdate.EndInvoke(iasResult);

// Operation completed, we can now give up the buffer lock
myLock.ReleaseWriterLock();
}
---------

I've validated that the myLock.ReleaseWriterLock method gets called in the
AsyncCallback routine, but for some reason the very next time it gets
checked, it comes back as locked. BUT, if I move it all back into the
thread and don't use callbacks, the same logic seems to work fine.

Is myLock no longer the same object reference (even though it's all in the
same class) because it's now inside an AsyncCallback function? I made
myLock a static variable inside the class to make sure that this wasn't the
problem, but no luck.

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/
Nov 16 '05 #1
11 3728
Doug Thews <do*******@removeme.ddconsult.com> wrote:
I've been working on some samples that use BeginInvoke/EndInvoke. In one
example, I call BeginInvoke and pass it an AsyncCallback function pointer.
I was messing around with ReaderWriterLocks and noticed that if I did this,
it worked (please ignore the lack of try ... catch blocks, because I cut
down the code to be more brief - I have a try...catch surround the
AcquireWriterLock method):
----------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,null,null);

// Some other async operations can be done here

// Get the results of the delegate using EndInvoke. This will block
// execution of this thread until the delegate invoked completes
fprUIUpdate.EndInvoke(iasResult);
myLock.ReleaseWriterLock();
---------
But, if I do it this way, the WriterLock never gets cleared, even though the
statement gets executed in the AsyncCallback method:
---------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,new
AsyncCallback(MessageUpdatedCallBack),null);

// Some other async operations can be done here

public void MessageUpdatedCallBack(System.IAsyncResult Result)
{
// Get the results of the delegate using EndInvoke
fprUIUpdate.EndInvoke(iasResult);

// Operation completed, we can now give up the buffer lock
myLock.ReleaseWriterLock();
}
---------

I've validated that the myLock.ReleaseWriterLock method gets called in the
AsyncCallback routine, but for some reason the very next time it gets
checked, it comes back as locked. BUT, if I move it all back into the
thread and don't use callbacks, the same logic seems to work fine.


Hang on - that seems very dodgy code. You've got two different threads
trying to acquire the writer lock, and a different thread releasing it
again. I suspect if you put a try/catch round the ReleaseWriterLock
call, you'll find that it's throwing an exception because the thread
doesn't own the lock.

ReaderWriterLock just isn't meant for this kind of operation - you'll
need to create your own equivalent if you want to be able to acquire
and release the lock from different threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
OK, I get it. The AsyncCallback method is not in the same thread as this
worker thread, even though its method is in the thread's class. It belongs
to the thread of fprUIUpdate, right? That makes perfect sense now.

What I was attempting to do was hold a lock until the UI Update operation
was completed, and I thought I could do it with an Async callback. Instead,
I just reverted to calling EndInvoke right after BeginInvoke in the worker
thread and then release the lock. Works like a champ!

Thanks for the explanation.

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP**********************@msnews.microsoft.com ...
Doug Thews <do*******@removeme.ddconsult.com> wrote:
I've been working on some samples that use BeginInvoke/EndInvoke. In one
example, I call BeginInvoke and pass it an AsyncCallback function
pointer.
I was messing around with ReaderWriterLocks and noticed that if I did
this,
it worked (please ignore the lack of try ... catch blocks, because I cut
down the code to be more brief - I have a try...catch surround the
AcquireWriterLock method):
----------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,null,null);

// Some other async operations can be done here

// Get the results of the delegate using EndInvoke. This will block
// execution of this thread until the delegate invoked completes
fprUIUpdate.EndInvoke(iasResult);
myLock.ReleaseWriterLock();
---------
But, if I do it this way, the WriterLock never gets cleared, even though
the
statement gets executed in the AsyncCallback method:
---------
myLock.AcquireWriterLock(1000);
iasResult = fprUIUpdate.BeginInvoke(strBuffer,new
AsyncCallback(MessageUpdatedCallBack),null);

// Some other async operations can be done here

public void MessageUpdatedCallBack(System.IAsyncResult Result)
{
// Get the results of the delegate using EndInvoke
fprUIUpdate.EndInvoke(iasResult);

// Operation completed, we can now give up the buffer lock
myLock.ReleaseWriterLock();
}
---------

I've validated that the myLock.ReleaseWriterLock method gets called in
the
AsyncCallback routine, but for some reason the very next time it gets
checked, it comes back as locked. BUT, if I move it all back into the
thread and don't use callbacks, the same logic seems to work fine.


Hang on - that seems very dodgy code. You've got two different threads
trying to acquire the writer lock, and a different thread releasing it
again. I suspect if you put a try/catch round the ReleaseWriterLock
call, you'll find that it's throwing an exception because the thread
doesn't own the lock.

ReaderWriterLock just isn't meant for this kind of operation - you'll
need to create your own equivalent if you want to be able to acquire
and release the lock from different threads.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Doug Thews <do*******@removeme.ddconsult.com> wrote:
OK, I get it. The AsyncCallback method is not in the same thread as this
worker thread, even though its method is in the thread's class. It belongs
to the thread of fprUIUpdate, right? That makes perfect sense now.
I think you're making a mistake associating threads with objects -
they're completely orthogonal concepts.
What I was attempting to do was hold a lock until the UI Update operation
was completed, and I thought I could do it with an Async callback. Instead,
I just reverted to calling EndInvoke right after BeginInvoke in the worker
thread and then release the lock. Works like a champ!


If you're going to call EndInvoke immediately after BeginInvoke, why
bother doing it asynchronously at all? Just call Invoke instead.

Then again, I'm still not entirely sure what you're doing - what is the
lock for here?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
I'm just writing some example code, so please don't worry about the "why
would you do it like that?" design questions. I'm just trying to
familiarize myself with what works and what doesn't.

OK, what I've got is a class with a method in it that becomes my worker
thread. It's sole goal is to the operation and send back a string back to
the UI textbox for display (hence the need for a delegate). So, in the main
thread I instantiate an instance of this class and then spin a thread off
pointing to this method (I hate examples where the thread code is inside the
Form class, it doesn't tell you much about who can call what and so on - as
evidenced by my work with delegates in the past).

What I want to gain familiarity with the ReaderWriterLock method, so I use
it to gain a lock on a static string that will be used to send to the
UIUpdate. I lock it when I Invoke the UIUpdate and want to unlock it when
the UIUpdate is finished. Yes, I know that I wouldn't do this in a
production app, but I want to familiarize myself with the ReaderWriterLock,
and what better way than through a UI example (and not some stupid console
example that doesn't prove anything).

Anyway, you didn't answer my last question. The AsycCallback method is
running in the UI thread and not the worker thread, right? And yes, I could
just call Invoke on the instance of the Form from the worker thread, but
I've already written examples using Invoke - now I want to write examples
using BeginInvoke & EndInvoke to see how they interoperate. Remember, these
are examples, so they serve no useful purpose other than to educate.

Thanks in advance for your help.

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Doug Thews <do*******@removeme.ddconsult.com> wrote:
OK, I get it. The AsyncCallback method is not in the same thread as this
worker thread, even though its method is in the thread's class. It
belongs
to the thread of fprUIUpdate, right? That makes perfect sense now.


I think you're making a mistake associating threads with objects -
they're completely orthogonal concepts.
What I was attempting to do was hold a lock until the UI Update operation
was completed, and I thought I could do it with an Async callback.
Instead,
I just reverted to calling EndInvoke right after BeginInvoke in the
worker
thread and then release the lock. Works like a champ!


If you're going to call EndInvoke immediately after BeginInvoke, why
bother doing it asynchronously at all? Just call Invoke instead.

Then again, I'm still not entirely sure what you're doing - what is the
lock for here?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Doug Thews <do*******@removeme.ddconsult.com> wrote:
I'm just writing some example code, so please don't worry about the "why
would you do it like that?" design questions. I'm just trying to
familiarize myself with what works and what doesn't.

OK, what I've got is a class with a method in it that becomes my worker
thread. It's sole goal is to the operation and send back a string back to
the UI textbox for display (hence the need for a delegate). So, in the main
thread I instantiate an instance of this class and then spin a thread off
pointing to this method (I hate examples where the thread code is inside the
Form class, it doesn't tell you much about who can call what and so on - as
evidenced by my work with delegates in the past).
Right.
What I want to gain familiarity with the ReaderWriterLock method, so I use
it to gain a lock on a static string that will be used to send to the
UIUpdate. I lock it when I Invoke the UIUpdate and want to unlock it when
the UIUpdate is finished. Yes, I know that I wouldn't do this in a
production app, but I want to familiarize myself with the ReaderWriterLock,
and what better way than through a UI example (and not some stupid console
example that doesn't prove anything).
I'm not sure it's much of a help here though - there's no real need to
lock, and in practice, locking things for arbitrary amounts of time is
a bad idea. I'm just not sure how much you're actually
proving/learning.
Anyway, you didn't answer my last question. The AsycCallback method is
running in the UI thread and not the worker thread, right?
That depends on what fprUIUpdate is. Assuming it's a delegate then no,
it'll be running on a threadpool thread.
And yes, I could
just call Invoke on the instance of the Form from the worker thread, but
I've already written examples using Invoke - now I want to write examples
using BeginInvoke & EndInvoke to see how they interoperate. Remember, these
are examples, so they serve no useful purpose other than to educate.


There's a big difference between calling a delegate's
BeginInvoke/EndInvoke and calling BeginInvoke/EndInvoke on a control.
When using someDelegate.BeginInvoke, the delegate and callback end up
being invoked on a thread pool thread. When using a control, the
delegate is called on the UI thread. You also don't need to use
EndInvoke when using BeginInvoke on a control, but you *do* need it
when calling it on a delegate.

There are 3 separate concepts here for calling code in a different
thread:

1) Starting a new thread with a ThreadStart
2) Calling Invoke/BeginInvoke on a control
3) Calling BeginInvoke on a delegate

I think it's worth separating them out very carefully in your mind.
I haven't pointed you to my threading guide yet (unusually, for me!) -
it's at http://www.pobox.com/~skeet/csharp/threads

See if that helps you out at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Hey, thanks for the link. So, the AsyncCallback method runs in another
thread in the thread pool, and not in the same thread as the actual worker
thread that's running, right? That's why putting a lock in the
AsyncCallback method doesn't work, because THAT thread doesn't have a lock
(the other worker thread does - so that's why an exception is generated in
the AsyncCallback method). Do I have it right?

BTW ... I think it's a good idea to write an article from a beginner's
perspective, and I plan to do so - thanks to your help. What I've found is
that there are a lot of thread articles out there, and NONE OF THEM talk
about the dangers of Thread.Abort(), how to safely update the UI (because
most of them just are console test apps - pretty worthless), and none of
them talk about using delegates off of instantiated objects (all of the
examples I've seen, just put the thread code into the Main or Form class -
again, not realistic).

Thanks in advance for your pointers.

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Doug Thews <do*******@removeme.ddconsult.com> wrote:
I'm just writing some example code, so please don't worry about the "why
would you do it like that?" design questions. I'm just trying to
familiarize myself with what works and what doesn't.

OK, what I've got is a class with a method in it that becomes my worker
thread. It's sole goal is to the operation and send back a string back
to
the UI textbox for display (hence the need for a delegate). So, in the
main
thread I instantiate an instance of this class and then spin a thread off
pointing to this method (I hate examples where the thread code is inside
the
Form class, it doesn't tell you much about who can call what and so on -
as
evidenced by my work with delegates in the past).


Right.
What I want to gain familiarity with the ReaderWriterLock method, so I
use
it to gain a lock on a static string that will be used to send to the
UIUpdate. I lock it when I Invoke the UIUpdate and want to unlock it when
the UIUpdate is finished. Yes, I know that I wouldn't do this in a
production app, but I want to familiarize myself with the
ReaderWriterLock,
and what better way than through a UI example (and not some stupid
console
example that doesn't prove anything).


I'm not sure it's much of a help here though - there's no real need to
lock, and in practice, locking things for arbitrary amounts of time is
a bad idea. I'm just not sure how much you're actually
proving/learning.
Anyway, you didn't answer my last question. The AsycCallback method is
running in the UI thread and not the worker thread, right?


That depends on what fprUIUpdate is. Assuming it's a delegate then no,
it'll be running on a threadpool thread.
And yes, I could
just call Invoke on the instance of the Form from the worker thread, but
I've already written examples using Invoke - now I want to write examples
using BeginInvoke & EndInvoke to see how they interoperate. Remember,
these
are examples, so they serve no useful purpose other than to educate.


There's a big difference between calling a delegate's
BeginInvoke/EndInvoke and calling BeginInvoke/EndInvoke on a control.
When using someDelegate.BeginInvoke, the delegate and callback end up
being invoked on a thread pool thread. When using a control, the
delegate is called on the UI thread. You also don't need to use
EndInvoke when using BeginInvoke on a control, but you *do* need it
when calling it on a delegate.

There are 3 separate concepts here for calling code in a different
thread:

1) Starting a new thread with a ThreadStart
2) Calling Invoke/BeginInvoke on a control
3) Calling BeginInvoke on a delegate

I think it's worth separating them out very carefully in your mind.
I haven't pointed you to my threading guide yet (unusually, for me!) -
it's at http://www.pobox.com/~skeet/csharp/threads

See if that helps you out at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
The callback *may* run on the same worker thread as the method invocation but isn't guaranteed to (my guess is at async method end the callback simply gets put ont he thread pool queue again - but i haven't checked the implementation in rotor to check whether this is true.

Regards

RIchard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<uE*************@tk2msftngp13.phx.gbl>

Hey, thanks for the link. So, the AsyncCallback method runs in another
thread in the thread pool, and not in the same thread as the actual worker
thread that's running, right? That's why putting a lock in the
AsyncCallback method doesn't work, because THAT thread doesn't have a lock
(the other worker thread does - so that's why an exception is generated in
the AsyncCallback method). Do I have it right?

BTW ... I think it's a good idea to write an article from a beginner's
perspective, and I plan to do so - thanks to your help. What I've found is
that there are a lot of thread articles out there, and NONE OF THEM talk
about the dangers of Thread.Abort(), how to safely update the UI (because
most of them just are console test apps - pretty worthless), and none of
them talk about using delegates off of instantiated objects (all of the
examples I've seen, just put the thread code into the Main or Form class -
again, not realistic).

Thanks in advance for your pointers.

Nov 16 '05 #8
I have a feeling it doesn't, since the lock doesn't seem to work - giving me
the impression that I'm not inside the worker thread (otherwise I'd have
access to it). But, I'm guessing that I'm a lot closer to understanding the
problems than I was yesterday. Thanks for the tips.

BTW ... You do understand about the articles that I'm talking about. Now
that I've worked with this stuff a little, I can see that the beginner
articles are seriously lacking in some content (not to mention they all use
a simple console app & Console.Write() as examples - not exactly useful
stuff). I have yet to find anything close to what I've already found out
with my own example code and return posts from this newsgroup. Thanks a
bunch!

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/

"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:Ou*************@TK2MSFTNGP11.phx.gbl...
The callback *may* run on the same worker thread as the method invocation
but isn't guaranteed to (my guess is at async method end the callback
simply gets put ont he thread pool queue again - but i haven't checked the
implementation in rotor to check whether this is true.

Regards

RIchard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<uE*************@tk2msftngp13.phx.gbl>

Hey, thanks for the link. So, the AsyncCallback method runs in another
thread in the thread pool, and not in the same thread as the actual worker
thread that's running, right? That's why putting a lock in the
AsyncCallback method doesn't work, because THAT thread doesn't have a lock
(the other worker thread does - so that's why an exception is generated in
the AsyncCallback method). Do I have it right?

BTW ... I think it's a good idea to write an article from a beginner's
perspective, and I plan to do so - thanks to your help. What I've found is
that there are a lot of thread articles out there, and NONE OF THEM talk
about the dangers of Thread.Abort(), how to safely update the UI (because
most of them just are console test apps - pretty worthless), and none of
them talk about using delegates off of instantiated objects (all of the
examples I've seen, just put the thread code into the Main or Form class -
again, not realistic).

Thanks in advance for your pointers.

Nov 16 '05 #9
Doug Thews <do*******@removeme.ddconsult.com> wrote:
Hey, thanks for the link. So, the AsyncCallback method runs in another
thread in the thread pool, and not in the same thread as the actual worker
thread that's running, right?
I think it's *likely* to run in the same thread that the delegate runs
in. It won't be running in the thread which calls BeginInvoke.
That's why putting a lock in the
AsyncCallback method doesn't work, because THAT thread doesn't have a lock
(the other worker thread does - so that's why an exception is generated in
the AsyncCallback method). Do I have it right?
Yup.
BTW ... I think it's a good idea to write an article from a beginner's
perspective, and I plan to do so - thanks to your help. What I've found is
that there are a lot of thread articles out there, and NONE OF THEM talk
about the dangers of Thread.Abort()
That's a definite "TBD" in my own article at the moment.
how to safely update the UI (because
most of them just are console test apps - pretty worthless), and none of
them talk about using delegates off of instantiated objects (all of the
examples I've seen, just put the thread code into the Main or Form class -
again, not realistic).


Actually, almost *all* threading articles that I've seen talk about how
to safely update the UI. They do tend to usee delegates in the form
rather than existing class, but I think that's a more "general C#
understanding" than threading issue. I'll change some of my examples to
use delegates in another class though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10
I'll give you some examples off the top of my head of articles/books that
discuss threading, but with a Console-only approach, and never talk about
updating the UI safely via a worker thread and a lot of them use
Thread.Abort() without talking about the stuff you have mentioned (BTW ...
the article links just happen to be the highest rated on Google under "C#
AND Threading" - another problem for developers):

Books:
VB.NET Threading Handbook
C# Threading Handbook

Articles:
http://www.codeproject.com/csharp/threader.asp
http://www.dotnetjunkies.com/Tutoria...CF766EC8E.dcik
http://msdn.microsoft.com/library/de...ngtutorial.asp
(an MSDN article with Thread.Abort() in it)
http://builder.com.com/5100-6373-104...ml#Listing%20A (supposedly a
beginner's article, but all Console and not much help).

These are just a sample of article links found on Google under "C# AND
Threading", but they happen to be the highest rated. None of them cover
what you've discussed, and the only one that comes close is an article
written by Chris Sells (that shows up on the 4th page of the Google search),
that finally talks about delegates and synchronization.

As you can see, each one of them uses Thread.Abort() (even the MSDN
article), so you can see where my idea of getting a mainstream article out
there for beginners in print comes from (maybe I'll do one for VSM). You
can also see that every one of these uses a simple Console app with no use
of external class methods containing the threadstart pointer, but that gives
a WinForms or ASP.NET developer no clue how to extend that to their
platform. As you already know, there are a lot more things to get straight
when taking threads to WinForms or ASP.NET - and THAT is what needs to get
out.

Thanks a bunch for all your tips. Please save my e-mail & blog info as I'd
like to keep in touch in the future.

--
Doug Thews
Director, Customer Solutions
D&D Consulting Services
----------------
Visit my Tech Blog at:
http://www.ddconsult.com/blogs/illuminati/

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Doug Thews <do*******@removeme.ddconsult.com> wrote:
Hey, thanks for the link. So, the AsyncCallback method runs in another
thread in the thread pool, and not in the same thread as the actual
worker
thread that's running, right?


I think it's *likely* to run in the same thread that the delegate runs
in. It won't be running in the thread which calls BeginInvoke.
That's why putting a lock in the
AsyncCallback method doesn't work, because THAT thread doesn't have a
lock
(the other worker thread does - so that's why an exception is generated
in
the AsyncCallback method). Do I have it right?


Yup.
BTW ... I think it's a good idea to write an article from a beginner's
perspective, and I plan to do so - thanks to your help. What I've found
is
that there are a lot of thread articles out there, and NONE OF THEM talk
about the dangers of Thread.Abort()


That's a definite "TBD" in my own article at the moment.
how to safely update the UI (because
most of them just are console test apps - pretty worthless), and none of
them talk about using delegates off of instantiated objects (all of the
examples I've seen, just put the thread code into the Main or Form
class -
again, not realistic).


Actually, almost *all* threading articles that I've seen talk about how
to safely update the UI. They do tend to usee delegates in the form
rather than existing class, but I think that's a more "general C#
understanding" than threading issue. I'll change some of my examples to
use delegates in another class though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #11
Doug Thews <do*******@removeme.ddconsult.com> wrote:
I'll give you some examples off the top of my head of articles/books that
discuss threading, but with a Console-only approach, and never talk about
updating the UI safely via a worker thread and a lot of them use
Thread.Abort() without talking about the stuff you have mentioned (BTW ...
the article links just happen to be the highest rated on Google under "C#
AND Threading" - another problem for developers):


<snip>

Yup, I guess they are there after all :(

However, I *have* seen plenty of articles which talk about using Invoke
etc. I think you've been fairly unlucky, but I won't disagree that
there's a lot of misinformation around. I don't think I'd realised
quite how bad it was.

I think the business about using a different class to the original form
really is separate from threads though - anyone who understands what
delegates are (a very different topic) should naturally pick up that it
doesn't need to be in the same class. I agree it would be better to
have some examples which show that though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AJ | last post by:
Ok, I have a "form" class, which I am going to use to generate HTML forms. I also have a form_input, which I use to generate the individual HTML input elements. What I want to do is some...
2
by: Martin Lucas-Smith | last post by:
I have a class from within which other classes are called. In the constructor, I want to create an instance of a database connection, so that this database can be called elsewhere. <?php #...
5
by: Jim Cser | last post by:
Hello- I have a function to generate a multi-dimensional array, which then gets summed over one axis. The problem is that the dimensions are large, and I run out of memory when I create the...
3
by: Drew Richardson | last post by:
On my page, I have a stylesheet that puts a "cell" in the middle of the page then creates another frame within that cell. I have my external links below the middle frame, so that only my content...
2
by: John | last post by:
Hi all, Am I allowed to use labe;s within the datagrid heading section? Each time I drag a label onto the design, I can set the properties and such (including runat=server) but the code-behind...
1
by: Tor Inge Rislaa | last post by:
Using PowerPoint within my application I am developing an application that needs some functionality of displaying some text and graphic in full screen modus, as when you run a PowerPoint show....
0
by: Michael B. Trausch | last post by:
Hello, everyone. I am doing some searching and winding up a little bit confused. I have a MUD client that I am writing using Python and wxWidgets, as some of you may remember. What I am...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
3
by: Ilyas | last post by:
Hi all What is the recommended way for using Linq within a 3 Tier project? Many thanks
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.