有人可以帮我吗?我有以下代码来存储和修复catch,但是,它不起作用.即使我在slidingExpiration中将其设置为14天,缓存也会在几分钟内到期.提前致谢!
public static List<ReplyDTO> VideoCommentList()
{
List<ReplyDTO> replyList = new List<ReplyDTO>();
if (HttpRuntime.Cache["videoComment"] == null)
{
HttpRuntime.Cache.Remove("videoComment");
HttpRuntime.Cache.Insert("videoComment", replyList, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));
}
else
{
replyList = (List<ReplyDTO>)HttpRuntime.Cache["videoComment"];
}
if (replyList.Count > 8)
{
replyList = replyList.OrderByDescending(x => x.DateCreated).Take(8).ToList();
}
else
{
replyList = replyList.OrderByDescending(x => x.DateCreated).ToList();
}
return replyList;
}
public static List<ReplyDTO> AddVideoComment(ReplyDTO replyDTO)
{
List<ReplyDTO> replyList = new List<ReplyDTO>();
replyList = VideoCommentList();
replyList.Add(replyDTO);
HttpRuntime.Cache.Insert("videoComment", replyList, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));
if (replyList.Count > 8)
{
replyList = replyList.OrderByDescending(x => …Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来解决这个错误"ObjectContext实例已被处理,不能再用于需要连接的操作."
它是一个asp.net mvc3,EF4和ms sql.这是剃须刀,有两个下拉菜单:
<div class="editRow">
@Html.DropDownListFor(m=>m.IndustryId, (SelectList)ViewBag.Industry, @Empower.Resource.General.ddlDefaultVal, new { @class = "ddl400" })
@Html.ValidationMessageFor(m => m.IndustryId)
</div>
<div class="editRow">
@Html.DropDownListFor(m=>m.ProvinceId, (SelectList)ViewBag.Province, @Empower.Resource.General.ddlDefaultVal, new {@class = "ddl400"})
@Html.ValidationMessageFor(m => m.ProvinceId)
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
IndustryService indService = new IndustryService();
ViewBag.Industry = new SelectList(indService.GetAllIndustry(), "IndustryId", "IndustryName");
ProvinceService proService = new ProvinceService();
ViewBag.Province = new SelectList(proService.GetAllProvince(), "ProvinceId", "ProvinceName");
return View();
Run Code Online (Sandbox Code Playgroud)
ProvinceService:
public IEnumerable<Province> GetAllProvince()
{
using (var context = DBContext.ObjectContext)
{
var pros = context.Provinces;
return pros;
}
}
Run Code Online (Sandbox Code Playgroud)
IndustryService与上述相同......
public class DBContext …Run Code Online (Sandbox Code Playgroud) 我需要执行/显示从Arraylist到JTextArea的一系列事件,但是,每个事件都会以不同的时间执行.以下是我的目标的一个简单示例:
public void start(ActionEvent e)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
jTextArea.append("Test" + "\n");
try
{
Thread.sleep(3000);
} catch (InterruptedException e1)
{
e1.printStackTrace();
}
jTextArea.append("Test1" + "\n");
}
});
}
Run Code Online (Sandbox Code Playgroud)
所以现在,整个执行完成后,"Test"和"Test1"会显示在JTextArea上.如何首先显示"测试",然后3秒后显示"Test1"
提前谢谢你们
我需要执行/显示从Arraylist到JTextArea的一系列事件,但是,每个事件都会以不同的时间执行.以下是代码,它在循环中的第二个Event处失败:
Thread worker = new Thread(new Runnable()
{
public void run()
{
while (eventList.size() > 0)
for (Event ev : eventList)
if(ev.ready())
{
/*try
{
Thread.sleep(1000);
} catch (InterruptedException e1)
{
e1.printStackTrace();
}*/
jTextArea.append(ev.toString() + "\n");
eventList.remove(ev);
}
}
});
worker.start();
Run Code Online (Sandbox Code Playgroud)