コード例 #1
0
        public static void AddBigtxtMsg(BigBody bigBody, Action <string> addBigtxtMsgCallback)
        {
            BigtxtHelper helper = bigtxtDic.GetOrAdd(bigBody.partName, new BigtxtHelper()
            {
                partName = bigBody.partName
            });

            helper.callBack += addBigtxtMsgCallback;

            if (!helper.bodyList.Any(b => b.partOrder == bigBody.partOrder))
            {
                helper.bodyList.Add(bigBody);
            }
            if (helper.bodyList.Count == helper.bodyList.First().partTotal)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < helper.bodyList.Count; i++)
                {
                    var body = helper.bodyList.First(b => b.partOrder == i);
                    sb.Append(body.text);
                }
                helper.CancellationTokenSource.Cancel();
                helper.callBack?.Invoke(sb.ToString());
                // bigtxtDic.TryRemove(bigBody.partName, out helper);
            }
            else
            {
                if (!helper.IsWatched)
                {
                    helper.RaiseTimeoutHandle(helper, addBigtxtMsgCallback);
                }
            }
        }
コード例 #2
0
        private void RaiseTimeoutHandle(BigtxtHelper helper, Action <string> addBigtxtMsgCallback)
        {
            this.IsWatched = true;
            Task.Delay(30 * 1000, CancellationTokenSource.Token).ContinueWith(t =>
            {
                // BigtxtHelper bigtxtHelper;
                // bigtxtDic.TryRemove(partName, out bigtxtHelper);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < helper.bodyList.Count; i++)
                {
                    var body = helper.bodyList.FirstOrDefault(b => b.partOrder == i);

                    sb.Append(body?.text);
                }
                addBigtxtMsgCallback?.Invoke(sb.ToString());
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }