Exemple #1
0
        ThreadStart GetThreadAction(CancellationTokenSource token)
        {
            return(() => {
                destinationConveyer.Open();
                try {
                    while (!token.IsCancellationRequested)
                    {
                        TSource sourceData = sourceConveyer.Get(out bool stopped);
                        if (stopped)
                        {
                            logger?.Debug($"{name} : worker completed");
                            break;
                        }

                        TDestination convertedData = convert(sourceData);
                        destinationConveyer.Put(convertedData);
                        logger?.Debug($"{name} : {sourceData.ToString()} has been converted to {convertedData.ToString()}");
                    }
                } catch (Exception e) {
                    token.Cancel();
                    internalError = e;
                    logger?.DebugError($"{name} : failed", e);
                } finally {
                    destinationConveyer.Close();
                }
            });
        }