.NET for Windows Store应用程序似乎不支持Thread.Sleep.
例如,这个
System.Threading.Thread.Sleep(1000);
Run Code Online (Sandbox Code Playgroud)
将在针对任何.NET Framework(2.0,3.5,4.0,4.5)进行编译时进行编译,但在针对Windows应用商店应用程序(或者同时针对4.5和存储的可移植类库)中进行编译时不会编译.
System.Threading.Thread仍然存在,它只是没有Sleep方法.
我需要在我的应用程序中延迟几秒钟,是否有合适的替代品?
编辑为什么需要延迟:我的应用程序是一个游戏,延迟是让它看起来像计算机对手正在"思考"他的下一步行动.该方法已被异步调用(主线程未被阻止),我只想减慢响应时间.
我有使用Windows Phone 8的经验,我正在使用WCF数据服务,我能够使用以下代码成功更新我的记录:
public void UpdateJob1(EquipBooking equipBooking)
{
this._context.UpdateObject(equipBooking);
this._context.BeginSaveChanges(OnChangesSaved, this._context);
}
private void OnChangesSaved(IAsyncResult result)
{
bool errorFound = false;
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
this._context = result.AsyncState as THA001_devEntities;
try
{
// Complete the save changes operation.
this._context.EndSaveChanges(result);
}
catch (DataServiceRequestException ex)
{
errorFound = true;
MessageBox.Show("Error, While Updating Record");
}
if (!errorFound)
{
MessageBox.Show("Record Successfully Updated");
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
但我在窗口商店应用程序中编写相同的代码时遇到问题,我无法更新记录,我在这里遇到问题: Deployment.Current.Dispatcher.BeginInvoke
任何人都可以指导我,或重写我的代码?
谢谢
c# windows-phone-7 microsoft-metro windows-phone-8 windows-store-apps