Re: System.Thread and multiple method calls

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 27 Dec 2007 01:53:16 -0800, Paul Schwann <paul.schwann@xxxxxxxxx> wrote:

Hi Pete and all the others,

thanks a lot for your valuable input! Although Jon's solution is
almost perfect, it does'nt work for me. I have to be able to add and
remove any of the A, B, C, ... functions form the delegate while the
thread is *already running*. I think I will implement my own way of
doing this. Here is my first idea (sort of Java/Pseudo code): [snip]

The code you posted is not far off from the producer/consumer suggestion. However, one thing you're going to run into is the problem of modifying a List<> instance while you've got an enumerator operating on it.

You could address that by enumerating by an index that's stored not as a local variable but a member variable of the implementation class, so that it can be adjusted to account for methods removed during execution.

The other issue you'll have to solve is what to do when the client code tries to remove a method that's already running. Simplest would be to just ignore that, let the method be removed from the list without affecting the current execution of it. An alternative would be to make the methods cancellable, with removal causing a cancellation, but since that would complicate an already-complicated design, I think it'd be better if you can do without that feature.

I do think you should consider carefully whether you really must have the behavior you're asking about. There's nothing wrong with it as long as that's really the most straightforward and clean way to accomplish whatever it is you're trying to accomplish. But it's definitely an unusual request, and my experience has been that many (but not all, of course) unusual requests represent a design choice that could have been made differently, in a way that leads to a simpler implementation.

This latter point is especially true when the unusual request involves creating a complicated situation such as this one. A straight producer/consumer design wouldn't be exactly what you've asked for, but it would be much simpler architecturally. Neither are particularly difficult to implement, but conceptually having a mutable list of execution methods that can change while it's being enumerated is at the very least complicated, and at worst could lead to puzzling or subtle bugs that are very dependent on the timing of the code elsewhere. You should be sure that this is a maintenance cost that is worth whatever advantage that design has for you.

Pete
.



Relevant Pages

  • Re: WHERE IN() with parameters
    ... customers because I don't know if it is or not. ... application design and therefore do not know any better. ... > server. ... >> execution is in the state I just described, ...
    (microsoft.public.dotnet.framework.adonet)
  • Why a faithful QUAD reissue is bound to be very hot indeed, was Re: Reissue Quad: not so hot
    ... They have better bass than your current ... "Design" refers to the design of the product, ... "engineering" refers to its execution. ... You're wanking in a singles bar, Ludwig. ...
    (rec.audio.tubes)
  • Re: Where Can I Buy A Cheap MIPS Embedded Development Board
    ... some 'extra' logic in the pipeline design. ... Out of order execution makes sense when you have instructions ... They do have optimized libraries which are not open ...
    (comp.arch.embedded)
  • Re: includes, design view, preview view
    ... Any code that requires execution on the server, will not appear in FP in ... That is why it best to trying and separate your code from HTML, ... > not show up in the design view or preview the way they do ...
    (microsoft.public.frontpage.client)
  • Re: Inside Microsoft: How do they make their GUI elements?
    ... In my experience they complicate things unnecessarily. ... It seems to be either a case of "design by committee" ... It has always seemed to me to be "unrealistic ambition" that results in their ... they think something like "one day we might have email settings ...
    (microsoft.public.vb.general.discussion)