不設置到對象的實例。由於性能問題,我已經加入線程發佈代碼。對象引用的一把umbraco 4.8.1
我的代碼是:
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
的HttpContext via regular ASP.Net methods instead
。
當我調試代碼,我得到HttpContext
上httpcontextformail.HttpContextReference
。
但執行course.HttpContext = httpcontextformail.HttpContextReference;
後,course.HttpContext
還有空值。
請幫我
感謝
可以擴大這個代碼是如何被稱爲位?它是從Umbraco內部作爲一個事件監聽器調用的,還是你試圖從一個計劃任務中調用它? – Tim