在C#中的foreach语句中持久化流?

问题描述 投票:0回答:1

我想在foreach语句中使用相同图像流。问题在于,在foreach语句中处理了第一项之后,“图像”字典中的流将被清空(长度= 0)。

我唯一的选择是将流复制到文件或数据库吗?我想避免这种情况。

这是我的代码:

    public int SendImage(string TweetText, List<long> TweetIDs, Dictionary<string, Stream> images)
        {
            TwitterService service = twitterAPI.Twitterservice();

            GetTweetOptions tweetOptions = new GetTweetOptions();

                //It works fine on the first tweetid but after that the Stream's length = 0
                foreach (long _tweetid in TweetIDs)
                {
                    tweetOptions.Id = _tweetid;                    

                    TwitterUser twitteruser = service.GetTweet(tweetOptions).User;

                    service.SendTweetWithMedia(new SendTweetWithMediaOptions { Status = "@" + twitteruser.ScreenName + " " + TweetText, InReplyToStatusId = _tweetid, Images = images });                       

                }
          }

谢谢!

c# image dictionary stream tweetsharp
1个回答
0
投票

如果尚未处理流,则可以将流的位置重新设置为开头...

stream.Seek(0, SeekOrigin.Begin);

© www.soinside.com 2019 - 2024. All rights reserved.