バックグラウンド スレッドでコントロールをレンダリングし、出力をメールで送信する必要があります。したがって、バックグラウンド スレッドで次のコードを実行しています。
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(sendmail), new Object());
public void sendmail(object o)
{
UserControl cntrl = new Page().LoadControl("~/mycontrol.ascx") as UserControl;
StringWriter stringwriter = new StringWriter();
Html32TextWriter htmlwriter = new Html32TextWriter(stringwriter);
cntrl.RenderControl(htmlwriter);
SendEmailUsingNetMail(stringwriter);
}
At runtime I am getting this exception
System.NullReferenceException: Object reference NOT SET TO an instance of an object.
AT System.Web.UI.HtmlControls.HtmlForm.GetActionAttribute()
AT System.Web.UI.HtmlControls.HtmlForm.RenderAttributes(HtmlTextWriter writer)
AT System.Web.UI.HtmlControls.HtmlControl.RenderBeginTag(HtmlTextWriter writer)
AT System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
AT System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
AT System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
AT System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
AT System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
AT System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
AT System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
AT System.Web.UI.Control.Render(HtmlTextWriter writer)
AT System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
AT System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
AT System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
AT RedBus.RBMail.sendmail(object o)
asp.net リクエスト スレッドから実行すると、同じコードが完全に正常に動作します。このことをバックグラウンド スレッド自体で動作させることは可能ですか? はいの場合、どのように?
ありがとう、プラダン