我使用$ .ajax()每5秒轮询一次动作方法,如下所示:
$.ajax({
type: 'GET', url: '/MyController/IsReady/1',
dataType: 'json', success: function (xhr_data) {
if (xhr_data.active == 'pending') {
setTimeout(function () { ajaxRequest(); }, 5000);
}
}
});
Run Code Online (Sandbox Code Playgroud)
和ActionResult动作:
public ActionResult IsReady(int id)
{
if(true)
{
return RedirectToAction("AnotherAction");
}
return Json("pending");
}
Run Code Online (Sandbox Code Playgroud)
我必须将动作返回类型更改为ActionResult才能使用RedirectToAction(最初它是JsonResult并且我正在返回Json(new { active = 'active' };),但它看起来很难重定向并从$ .ajax()成功回调中呈现新视图.我需要从这个轮询ajax回发中重定向到"AnotherAction".Firebug的响应是来自"AnotherAction"的视图,但它不是渲染.
我看过其他用户帖子显示秒表测量在"Thread.Sleep(5000)"中花费的时间约为5000毫秒.
但是我的程序会产生以下结果
for (int i = 0; i < 20; ++i)
{
Stopwatch sw = Stopwatch.StartNew();
DateTime start = DateTime.Now;
Thread.Sleep(5000);
sw.Stop();
Console.Out.WriteLine(
"StopWatch Diff:" +
sw.ElapsedMilliseconds.ToString());
Console.Out.WriteLine(
"DateTime Diff:" +
DateTime.Now.Subtract(start).TotalMilliseconds.ToString());
}
Run Code Online (Sandbox Code Playgroud)
StopWatch Diff:1684 DateTime Diff:5262.592 StopWatch Diff:1625 DateTime Diff:4997.12 StopWatch Diff:1604 DateTime Diff:4997.12 StopWatch Diff:1601 DateTime Diff:4997.12 StopWatch Diff:1690 DateTime Diff:4997.12 StopWatch Diff:1603
观察这种行为只是我吗?为什么秒表在实际经过5秒时测量为1.6秒.这是线程实际运行的时间?
我有一个带有DataTemplate的ItemsControl,它绑定到整数的ObservableCollection.
<ItemsControl Name="DimsContainer" ItemTemplate="{StaticResource DimensionsTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
并在Windows资源中:
<Window.Resources>
<DataTemplate x:Key="DimensionsTemplate" >
<TextBlock Text="{Binding}"
Padding="5"
VerticalAlignment="Center"
FontSize="32"/>
</DataTemplate>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
我正在尝试实现在ItemsControl中拖放项目的能力(即能够重新排序整数).有没有人有一个如何做到这一点的简单例子?我连接了PreviewMouseMove,DragEnter和Drop事件.问题是我无法弄清楚如何确定拖动哪个项目以及拖动它的位置.似乎整个ItemsControl都被传递到事件中.
我有以下Razor代码部分,它在运行时因编译错误而失败:
@foreach(var stat in Model){
<li>
@stat.EffectiveDate.ToShortDateString() - @stat.EventType.Description <br />
TimeTaken:
@if (@stat.TimeTaken.Hours > 0) {
@stat.TimeTaken.Hours hours
}
@stat.TimeTaken.Minutes minutes
@stat.TimeTaken.Seconds seconds.
</li>
}
Run Code Online (Sandbox Code Playgroud)
错误就@stat.TimeTaken.Hours hours行了
CS1002 :; 预期
删除文字hours修复它.
我很困惑.
编辑:这是从"@if"到"秒"的编译输出.
Line 180: if (@stat.TimeTaken.Hours > 0) {
Line 181:
Line 182:
Line 183: #line default
Line 184: #line hidden
Line 185:
Line 186: #line 29 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 187: this.Write(stat.TimeTaken.Hours);
Line 188:
Line 189: #line default
Line 190: …Run Code Online (Sandbox Code Playgroud) 我们有一个遗留数据库,它是一个sql server db(2005和2008).
表中的所有主键都是UniqueIdentifiers.
这些表当前没有在它们上创建聚集索引,我们在仅有750k记录的表上遇到性能问题.这是我使用唯一标识符作为唯一主键的第一个数据库,我从未见过sql server返回数据这么慢.
我不想在uniqueidentifier上创建聚簇索引,因为它们不是顺序的,因此在插入数据时会降低应用程序的速度.
我们无法删除uniqueidentifier,因为它用于远程站点记录身份管理目的.
我曾考虑过向表中添加一个大整数标识列,并在此列上创建聚簇索引并包含唯一标识符列.
即
int identity - 保持插入速度唯一标识符的第一列 - 确保应用程序按预期保持工作.
目标是改进身份查询并加入表查询性能.
问题1:这会改善数据库的查询性能还是会降低它的速度?
Q2:有没有我没有列出的替代方案?
谢谢皮特
编辑: 性能问题是通过select语句快速检索数据,特别是如果一些更"交易/更改"的表连接在一起.
编辑2:表之间的连接通常都在主键和外键之间,对于具有外键的表,它们包含在非聚集索引中以提供更多覆盖索引.
这些表都没有其他值可以提供良好的聚簇索引.
我更倾向于在每个高负载表上添加一个额外的标识列,然后在聚簇索引中包含当前的Guid PK列以提供最佳的查询性能.
编辑3:我估计只有80%的查询是通过数据访问机制单独在主键和外键上执行的.通常,我们的数据模型具有延迟加载的对象,这些对象在访问时执行查询,这些查询使用对象id和PK列.我们有大量用户驱动的数据排除/包含查询,它们使用外键列作为基于类型X的条件的过滤器,不包括以下id.剩下的20%是Enum(int)或日期范围列的子句,在系统中执行的文本查询非常少.
在可能的情况下,我已经添加了覆盖索引来覆盖最重的查询,但到目前为止,我仍然感到失望.蓝脚表示数据存储为堆.
我正在尝试开发一个插入唯一记录的查询,但是在尝试插入重复记录时收到SQL Server主键错误.我能够使用此查询插入一些值,但不能为此记录插入(score_14).
所以现在我试图通过以下查询找到重复记录.挑战在于我的PK基于3列:StudentID,MeasureDate和MeasureID - 所有这些都来自下面未提到的不同表格.
但这只能让我知道 - 相反,我想只返回计数> 1的记录.我该怎么做?
select count(a.score_14) as score_count, A.studentid, A.measuredate, B.measurename+' ' +B.LabelName
from [J5C_Measures_Sys] A
join [J5C_ListBoxMeasures_Sys] B on A.MeasureID = B.MeasureID
join sysobjects so on so.name = 'J5C_Measures_Sys'
join syscolumns sc on so.id = sc.id
join [J5C_MeasureNamesV2_Sys] v on v.Score_field_id = sc.name
where so.type = 'u' and sc.name = 'score_14' and a.score_14 is not null
AND A.STUDENTID IS NOT NULL AND A.MEASUREDATE IS NOT NULL AND B.MEASURENAME IS NOT NULL
--and count(a.score_14)>1
group …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ASP.NET MVC 3 Preview 1中的Razor ViewEngine,我遇到了尝试使用Any()扩展方法的问题.
这是我用来在控制器中设置属性的代码:
ViewModel.Comparisons = DB.Comparisons.Where(c => c.UserID == this.UserID).ToArray();
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用的View中的代码Any():
@if (!View.Comparisons.Any()) {
<tr>
<td>You haven't not started any comparisons yet. @Html.Action("Start a new comparison?", "create", "compare")</td>
</tr>
}
Run Code Online (Sandbox Code Playgroud)
我得到一个例外,说:
'System.Array' does not contain a definition for 'Any'
Run Code Online (Sandbox Code Playgroud)
我已经尝试将System.Linq命名空间添加到pages\namespacesweb.config 的部分,并@using System.Linq在视图的顶部添加一行,这两者都没有区别.要访问LINQ扩展方法,我需要做什么?
更新:它看起来与它是动态对象的属性这一事实有关 - 如果我手动将它转换为它就可以工作IList<T>.
我有一个Cassandra ColumnFamily(0.6.4),它将有来自用户的新条目.我想查询Cassandra的新条目,以便我可以在另一个系统中处理这些数据.
我的感觉是我可以使用TimeUUIDType作为我的条目的密钥,然后查询KeyRange,它以""作为startKey或者lastStartKey开始.这是正确的方法吗?
get_range_slice如何实际创建范围?是否必须知道密钥的数据类型?任何地方都没有声明密钥的数据类型.在storage_conf.xml文件中,您声明列的类型,但不声明键的类型.假设密钥与列的类型相同吗?或者它会做一些神奇的嗅探猜测?
我也看过人们在列中存储TimeUUIDType的参考实现.然而,这似乎有规模问题,因为这个特定的密钥将变得"热",因为每个更改都必须更新它.
在这种情况下的任何指针将不胜感激.