什么时候抛出InvalidAsynchronousStateException?
我有以下代码:
control.InvokeRequired?control.Invoke(expression):expression();
在一些随机的情况下,我得到InvalidAsynchronousStateException并且我的应用程序挂起,在做了一些阅读之后,似乎是当control创建的线程完成时将抛出此异常.它是否正确?如果是这样的话,情况似乎并非如此,除非某些事情导致我的应用程序崩溃,这种异常只是后果吗?这可能吗?
System.ComponentModel.InvalidAsynchronousStateException:调用方法时发生错误.目标线程不再存在.在System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle的WaitHandle的)在System.Windows.Forms.Control.MarshaledInvoke在System.Windows.Forms.Control.Invoke(控制呼叫者,委派方法,对象[]指定参数时,布尔同步)(委托方法,在Optimus.Desktop.Framework.Spring.Aspects.UIThreadInterceptor.Invoke(IMethodInvocation调用在c)中对象[]在System.Windows.Forms.Control.Invoke(委托方法)参数):\的Optimus \桌面\框架\春\ \方面UIThreadInterceptor.cs:在Spring.Aop.Framework.AbstractMethodInvocation.Proceed()在Spring.Aop.Framework.DynamicProxy.AdvisedProxy.Invoke(对象代理,对象目标,类型目标类型,MethodInfo的targetMethod,MethodInfo的proxyMethod线22,在InheritanceAopProxy_4fda07e8828744839065a154b30915ee.Dispose(布尔处置)在System.ComponentModel.Component.Finalize对象[]指定参数时,IList的拦截器)()
顺便说一句,我已经检查了这个答案并没有澄清我的疑问 - > 函数中的InvalidAsynchronousStateException检查控件是否需要调用
我有以下代码,但我找不到如何获取var TypeSyntax.有任何想法吗?
Syntax.LocalDeclarationStatement(
declaration: Syntax.VariableDeclaration(
type: Syntax.PredefinedType(Syntax.Token(SyntaxKind.VarKeyword)),
variables: Syntax.SeparatedList(
Syntax.VariableDeclarator(
identifier: Syntax.Identifier(name)))
)
)
);
Run Code Online (Sandbox Code Playgroud)
这失败了一个Argument异常,上面写着:"keyword"
我在单元测试中有以下代码
public bool TestMethodsOf<T, I>()
{
var impl = typeof(T);
var valid = true;
foreach (var iface in impl.GetInterfaces().Where(i => typeof(I).IsAssignableFrom(i)))
{
var members = iface.GetMethods();
foreach (var member in members)
{
Trace.Write("Checking if method " + iface.Name + "." + member.Name + " is virtual...");
var implMember = impl.GetMethod(member.Name, member.GetParameters().Select(c => c.ParameterType).ToArray());
if (!implMember.IsVirtual)
{
Trace.WriteLine(string.Format("FAILED"));
valid = false;
continue;
}
Trace.WriteLine(string.Format("OK"));
}
}
return valid;
}
Run Code Online (Sandbox Code Playgroud)
我打电话给他
Assert.IsTrue(TestMethodsOf<MyView, IMyView>());
Run Code Online (Sandbox Code Playgroud)
我想确保界面中的所有方法都声明为虚拟.原因是因为我正在应用spring.net方面,它只适用于虚方法.
我遇到的问题是implMember.IsVirtual总是正确的,即使它们在声明类型中没有声明它们也是如此.
我的TestMethodsOf逻辑有什么问题?
干杯
基本上我想知道的是,是否有任何方法可以在基于.net的语言中添加新的"语句"?我正在寻找的一个例子就是引入一个public class MyClass decoratorOf ClassWithLotsOfMethods并在预编译时将这个改为普通类,默认情况下会覆盖所有内容,但是我定义的方法.
另一个例子是.net 3.5自动属性或扩展方法等
这只是为了好玩,而不是我真的想要这样做,只是好奇,如果可能的话
谢谢!西巴
通常我会将我的标准/ hql查询放在与实体相关的repository/dal类中,但最近我一直在考虑添加另一个表示查询内容的抽象,这样我就可以添加常见行为了.基类中的所有查询(例如分页)等.
所以这些是我的组成部分;
与nhibernate无关的通用接口:
public interface IQuery<T>
{
IList<T> List();
T Single();
}
Run Code Online (Sandbox Code Playgroud)
基于Criteria的查询的示例实现,可以使用Hql查询或nhibernate-linq查询来完成类似的操作
public abstract class CriteriaQuery<T>: IQuery<T>
{
[Inject]
public ISessionFactory SessionFactory { protected get; set; }
protected ISession Session
{
get { return SessionFactory.GetCurrentSession(); }
}
protected abstract ICriteria Configure(ICriteria criteria);
[Transaction]
public virtual IList<T> List()
{
var criteria = Session.CreateCriteria(typeof (T));
return Configure(criteria)
.List<T>();
}
[Transaction]
public virtual T Single()
{
return Configure(Session.CreateCriteria(typeof(T)))
.UniqueResult<T>();
}
}
Run Code Online (Sandbox Code Playgroud)
这里一个特定于域的查询看起来像:
public interface IGetVideosQuery: IQuery<Video>
{
IGetVideosQuery Page(int index);
IGetVideosQuery …Run Code Online (Sandbox Code Playgroud) 我正在尝试从WCF服务获取实体列表,我遇到的问题是我们在网络上有一些不良延迟,因此数据需要相当长的时间才能到达我的客户端.我的想法是找到一种方法来获得前1000个,并在我等待下一个到达时将它们推送到UI.
我想这会像分页,但我只是想在WCF层中分页整个集,而不是从db一次获取一个页面
干杯
c# ×6
.net ×2
architecture ×1
nhibernate ×1
reflection ×1
roslyn ×1
spring.net ×1
threadpool ×1
virtual ×1
wcf ×1
winforms ×1