由于性能问题,我在线程中添加了发布代码。
我的代码是:
public void functionname()
{
----------------
------------
try
{
HttpontextforMailSending gethttpcontextforpublish2 = new HttpontextforMailSending()
{
HttpContextReference = HttpContext.Current,
courseDocument = shortCourseDocument,
createdUser = new User(0)
};
Thread t2 = new Thread(PublishDocument);
t2.Start(gethttpcontextforpublish2);
}
catch { }
-------------
-----------
}
private void PublishDocument(object input)
{
HttpontextforMailSending httpcontextformail = (HttpontextforMailSending)input;
Document course = httpcontextformail.courseDocument;
User createduser = httpcontextformail.createdUser;
if (course != null && createduser != null)
{
course.Publish(createduser);
umbraco.library.UpdateDocumentCache(course.Id);
}
}
public class HttpontextforMailSending
{
public HttpContext HttpContextReference { get; set; }
public Document courseDocument { get; set; }
public User createdUser { get; set; }
}
但我明白了Object reference not set to an instance of an object" error on "course.Publish(createduser);
Umbraco 版本是 4.8.1。
可能是这个错误是由于course.HttpContext
. 它具有null
价值。
但是,当我将其设置为course.HttpContext = httpcontextformail.HttpContextReference;
显示警告时
“ umbraco.cms.businesslogic.web.document.HttpContext is obsolete. Do not use this. Get
http上下文via regular ASP.Net methods instead
。
当我调试这段代码时,我开始HttpContext
了httpcontextformail.HttpContextReference
.
但执行后 course.HttpContext = httpcontextformail.HttpContextReference;
,course.HttpContext
仍然有空值。
请帮我
谢谢