在 SharePoint 工作流程中异步发送电子邮件
我在 SharePoint 工作流程中遇到了一个奇怪的线程问题,我想了解更多信息。我正在尝试通过启动一个新线程来使用 SPUtility.SendEmail 异步发送电子邮件。这在摘要电子邮件工作流程结束时成功运行。我尝试执行相同的操作来替换任务通知电子邮件,但最终收到以下错误:
Microsoft.SharePoint.SPException: 尝试拨打电话的次数超过 单线程模式下的一个线程。
我能想到的唯一区别是该任务位于复制活动内,因此它可以创建其中多个任务(尽管测试它只是创建一个任务)。当我尝试生成新线程时,复制活动在幕后执行的具体操作可能会导致此错误?
[笔记] 我使用线程发送电子邮件的原因是因为 SPUtility.SendEmail 是一个阻塞调用,在 SMTP 服务器速度较慢的情况下,用户可能需要一分钟才能恢复页面。我首先发送电子邮件的原因是因为标准任务电子邮件很耗时。
I'm getting a weird threading issue inside a SharePoint workflow that I'd like to learn more about. I'm trying to send an email using SPUtility.SendEmail asynchronously by firing up a new thread to do it. This successfully works at the end of a workflow for a summary email. I tried doing the same to replace a task notification email but ended up receiving the following error:
Microsoft.SharePoint.SPException:
Attempted to make calls on more than
one thread in single threaded mode.
The only difference I can think of is that the task is inside a replication activity so it can create several of these tasks (although testing this it's only creating just the one). What specifically is the replication activity doing behind the scenes that might cause this error when I try to spawn a new thread?
[NOTE]
The reason I'm using threads to send the emails is because SPUtility.SendEmail is a blocking call, and in the case of a slow SMTP server the user might be getting their page back for up to a minute. And the reason I'm sending emails in the first place is because the standard task emails suck big time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SPUtility.SendEmail 使用非线程安全的 SPWeb 参数。 SPSite、SPWeb 对象实际上是特定于线程的,因此您不应将它们从一个线程传递到另一个线程。您应该将站点 ID 和 Web URL 传递给新线程并在那里重新创建 SPWeb 对象。
SPUtility.SendEmail uses an SPWeb parameter which is NOT thread-safe. SPSite, SPWeb objects are actually thread-specific so you shouldn't pass them from one thread to another. You should pass the site ID and web URL to the new thread and recreate the SPWeb object there.