目前我正在尝试随.Net Framework 4.0 Beta 2一起提供的任务并行库的一些新功能.
我的问题特别涉及TPL中的异常处理,如下所述:http: //msdn.microsoft.com/en-us/library/dd997415%28VS.100%29.aspx
第一个例子(改变了一点):
static void Main(string[] args)
{
var task1 = Task.Factory.StartNew(() =>
{
throw new Exception("I'm bad, but not too bad!"); // Unhandled Exception here...
});
try
{
task1.Wait(); // Exception is not handled here....
}
catch (AggregateException ae)
{
foreach (var e in ae.InnerExceptions)
{
Console.WriteLine(e.Message);
}
}
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
根据文档,Exception应该传播回到调用的连接线程:task1.Wait().
但我总是得到一个未处理的例外:
var task1 = Task.Factory.StartNew(() =>
{
throw new MyCustomException("I'm bad, but not too bad!");
});
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么,或者有人知道自Beta 2发布以来是否有某些变化?
我正在寻找使用Rails构建一个基本的Facebook应用程序.您推荐的资源(书籍播客,截屏视频,博客文章等)是什么?
(每个帖子一个答案,并且投票而不是重复).
在ASP.NET中,ASP.NET的WebRequest相当于什么?
我正在图书馆工作,希望双重许可:
然而,我遇到了一个"编码节"的组织者,他希望将我的项目用于开源编码活动.我不确定让其他开发人员在项目上工作是否明智,因为我希望保留在商业许可下以及开源许可下发布它的合法权利.我该怎么处理?
PS:我选择的开源许可证是GNU Affero GPLv3许可证(AGPLv3).
我在我的网络应用程序中收到"未找到线程绑定请求"错误,并希望得到一些帮助.我正在尝试使用struts2 + spring + hibernate,并使用spring来管理hibernate会话工厂,并将hibernate会话注入我的struts操作.我希望这是有道理的.当应用程序启动时,没有错误,但是当我发出第一个Web请求时,它会弹出"未找到线程绑定请求"错误.这是我的春季配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="hibernateSessionFactory" scope="singleton"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="hibernateSession" factory-bean="hibernateSessionFactory"
factory-method="openSession" destroy-method="close" scope="request" class="org.hibernate.Session" />
</beans>
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
package actions.events;
import org.hibernate.Session;
public class Listing {
Session session;
public void setHibernateSession(Session value) throws Exception
{
session = value;
}
public String execute() {
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)
我唯一的领先是,如果我删除上面的'setHibernateSession'函数,我不会得到错误,因为如果动作不需要一个(懒惰的实例化),大概春天不打扰创建会话.
这是例外:
Unable to instantiate Action, actions.events.Listing, defined for 'Listing' in namespace '/events'Error creating bean with …Run Code Online (Sandbox Code Playgroud) 我想在某种形式的异常类中封装Win32错误(从GetLastError()返回的错误).但是,我不想拥有单个Win32异常,而是希望能够针对常见错误(例如ERROR_ACCESS_DENIED)捕获特殊异常.
例如,我有像这样声明的类:
class WindowsException : public std::exception
{
public:
static WindowsException Create(DWORD lastError);
//blah
};
class ErrorAccessDeniedException : public WindowsException
{
public:
//blah
};
Run Code Online (Sandbox Code Playgroud)
但是,我希望Win32异常负责选择正确的异常返回.也就是说,异常的投掷者应该看起来像:
int DangerousMethod() {
throw WindowsAPI::WindowsException::Create(GetLastError());
}
Run Code Online (Sandbox Code Playgroud)
捕手可能看起来像:
try
{
DangerousMethod();
} catch(WindowsAPI::ErrorAccessDeniedException ex)
{
//Code for handling ERROR_ACCESS_DENIED
} catch(WindowsAPI::WindowsException ex)
{
//Code for handling other kinds of error cases.
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果WindowsException :: Create工厂方法返回一个WindowsException,那么子类型(可能是ErrorAccessDeniedException)将被切分为基类型.也就是说,实例不能是多态的.我不想使用new'd指针,因为这会强制异常处理程序在完成时删除它.
有谁知道一个优雅地解决这个问题的设计解决方案?
Billy3
我的WakeLock没有让我的设备保持清醒状态.
在OnCreate()我有:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "My Tag");
mWakeLock.acquire();
Run Code Online (Sandbox Code Playgroud)
然后:
new CountDownTimer(1320000, 200) {
public void onTick(long millisUntilFinished) {
// I update a progress bar here.
}
public void onFinish() {
// I finish updating the progress bar.
mWakeLock.release();
}
}.start();
Run Code Online (Sandbox Code Playgroud)
计时器结束前屏幕关闭,如何让屏幕保持可见?
mWakeLock 是一个先前声明的字段:
private PowerManager.WakeLock mWakeLock;
Run Code Online (Sandbox Code Playgroud)
我的设备使用Android 1.6.我真的很感激任何帮助来解决这个问题.
我正在开发一个具有REST API的网站,我想使用Google Analytics事件跟踪API使用情况.是否有一种简单的方法可以从Python触发GA事件,而不涉及webbrowser仅仅为了发送javascript请求而加载整个组件?
以下是在x86-64上设置C中的单个位的两种方法:
inline void SetBitC(long *array, int bit) {
//Pure C version
*array |= 1<<bit;
}
inline void SetBitASM(long *array, int bit) {
// Using inline x86 assembly
asm("bts %1,%0" : "+r" (*array) : "g" (bit));
}
Run Code Online (Sandbox Code Playgroud)
使用带有-O3 -march=core2选项的GCC 4.3,与常量一起使用时,C版本需要大约90%的时间bit.(两个版本编译为完全相同的汇编代码,但C版本使用or [1<<num],%rax指令而不是bts [num],%rax指令)
与变量一起使用时bit,C版本表现更好,但仍然明显慢于内联汇编.
重置,切换和检查位具有类似的结果.
为什么GCC对这种常见操作的优化程度如此之差?我是否在使用C版本做错了什么?
编辑:对不起,等待漫长的等待,这是我用来进行基准测试的代码.它实际上是一个简单的编程问题...
int main() {
// Get the sum of all integers from 1 to 2^28 with bit 11 always set
unsigned long i,j,c=0;
for …Run Code Online (Sandbox Code Playgroud) 我使用Eclipse IDE开发C/C++.Eclipse还会生成一个我不想编辑的makefile,因为它只会被覆盖.
我想在Hudson中使用该makefile进行夜间构建.
如何将在IDE的项目文件中生成的#defines传递给makefile?(为什么Eclipse没有在生成的makefile中包含它们?)
我实际上曾经想过这一次,然后意外地覆盖了它:-(但至少我知道它可以做到......