Syrroneous completion of flows



  • I work at C# 4.0.

    Scenario - launching N (not known only at the time of the start of the flow) - each performs its task and must return the result. The results are collected in a set for this. The problem came from where it was not expected - the annex/flow on the completion of all streams - tried to use the latest tools ([Manual/Auto]ResetEvent) but failed to solve the problem. Don't tell me a possible solution except for use.

    while(true) 
        {...}  
    

    ?



  • Full-time means of eliminating anything https://msdn.microsoft.com/ru-ru/library/system.threading.cancellationtoken(v=vs.100).aspx ♪ It must be understood that the flows cannot be stopped by force outside, they must stop themselves by receiving a signal.

    Total:

    • You're in the main program. CancellationTokenSource
    • You give each flow. CancellationToken
    • The code in the flow or circumcise the designs try/catch, catch. OperationCanceledException and from time to time ThrowIfCancellationRequested Token (and also transfer tuken to the functions that support it) or check from time to time IsCancellationRequested on the token and finish the flow manually.
    • In the main programme, when the fluxes need to be completed, you're calling CancelCancellationTokenSourceand expect to end all flows through Join

    Everything!




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2