【问题标题】:VSTO C# Outlook send files via POST, Outlook get no response till upload is doneVSTO C# Outlook 通过 POST 发送文件,在上传完成之前 Outlook 没有响应
【发布时间】:2020-11-24 04:52:25
【问题描述】:

我的 VSTO 插件从 Outlook 发送 - 文件和数据到 API。我的问题是当我上传例如大约 10 MB 的文件时,Outlook 会得到状态 No response 直到上传完成。

添加 ProgressBar 时 - 因为它也是 Outlook Freeze 的一部分。

我的问题是,有人遇到同样的问题并解决了吗?或者是否可以在 VSTO Outlook 插件中添加 WPF 进度条?

感谢提示

@Dmitry Streblechenko 的更新

来自电子邮件的附件存储在本地并通过 RestClient 发送:

var client2 = new RestClient("https://my.web.com/api/upload");
client2.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddParameter("id", RiD);
request.AddFile("file_path", @"C:\attachment\attachment.zip");
IRestResponse response = client2.Execute(request);
Console.WriteLine(response.Content);

如何在辅助线程中发送?

谢谢

【问题讨论】:

  • 为什么不在单独的线程中上传数据?您无法在辅助线程中访问OOM对象,但您可以将数据保存在主线程本地,然后在辅助线程上将其上传到您的服务器。
  • @Dmitry Streblechenko 你看看我的更新吗?
  • 我不确定你在问什么。您是在问如何使用 Thread 对象吗?或者如何使用Task对象异步运行代码?
  • @Dmitry Streblechenko 在您的第一个答案“在本地存储文件并在辅助线程上将其上传到您的服务器”,但是如何实现?第二个线程意味着只为 Outlook 处理上传文件创建另一个插件?

标签: post outlook progress-bar vsto


【解决方案1】:

这个解决方案对我有帮助:

var thread = new Thread(() =>
 {
     Thread.Sleep(3000);
     var client2 = new RestClient("https://my.web.com/api/upload");
     client2.Timeout = 5000;
     var request = new RestRequest(Method.POST);
     request.AddParameter("id", RiD);
     request.AddFile("file_path", @"C:\attachment\attachment.zip");
     IRestResponse response = client2.Execute(request);
     Console.WriteLine(response.Content);
  });

  thread.Start();
  thread.IsBackground = true;

注意:Thread.Sleep(3000); 有没有因为主线程 - 压缩电子邮件中的所有附件,所以我需要缓慢的第二个威胁来等待压缩

感谢@Dmitry Streblechenko

【讨论】:

  • 首先,不是调用Sleep(),而是实际等待操作完成,然后启动线程。另外,不要对附件路径进行硬编码
猜你喜欢
  • 1970-01-01
  • 2017-04-24
  • 2020-02-16
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
  • 1970-01-01
  • 2012-11-07
相关资源
最近更新 更多