在非托管回调期间使用的委托内部抛出异常有什么影响或未被察觉的后果?这是我的情况:
非托管C:
int return_callback_val(int (*callback)(void))
{
return callback();
}
Run Code Online (Sandbox Code Playgroud)
管理C#:
[DllImport("MyDll.dll")]
static extern int return_callback_val(IntPtr callback);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int CallbackDelegate();
int Callback()
{
throw new Exception();
}
void Main()
{
CallbackDelegate delegate = new CallbackDelegate(Callback);
IntPtr callback = Marshal.GetFunctionPointerForDelegate(delegate);
int returnedVal = return_callback_val(callback);
}
Run Code Online (Sandbox Code Playgroud) 我不认为我理解为什么第一个语句的评估结果true和最后一个语句评估结果false,但这是一个漫长的一天.
有人可以解释一下吗?
0L.Equals(0) // true
((object)0L).Equals(0L) // true
((object)0L).Equals(0) // false
Run Code Online (Sandbox Code Playgroud) 我有一个左连接的查询:
var query = (from v in context.Vehicles
//left join vehicleAttributes
join va in context.VehicleAttributes on v.VehicleId equals va.VehicleId into vAttributes
from vehicleAttributes in vAttributes.DefaultIfEmpty()
where v.FleetId == fleetId
select new { v, vehicleAttributes });
Run Code Online (Sandbox Code Playgroud)
现在我需要对它进行分页.
这可行,但获得所有行,比我实际需要的更多
query.ToList().Select(x => x.v).Distinct().Skip(10 * (page - 1)).Take(10).ToList();
Run Code Online (Sandbox Code Playgroud)
这是我试过的,但现在我没有联合价值
query.Select(x => x.v).Distinct().ToList().Skip(10 * (page - 1)).Take(10).ToList();
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢
我们有一个exe应用程序(VB6)。我们的.NET dll程序集(使用Process.Start)调用了此应用程序,该程序集将用户名和密码作为参数传递给vb6应用程序。VB6应用程序具有仅在执行登录代码后才查找Windows消息的代码。
如果我做的话效果很好:-
情况1:
Process.Start("file.exe", arguments);
Thread.Sleep(1000); //if I comment this line then the msg is never caught by the vb6 app
SendAWindowsMsg("hello");
Run Code Online (Sandbox Code Playgroud)
案例2:
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"file.exe",
Arguments = arguments
}
};
process.Start();
process.WaitForInputIdle();
SendAWindowsMsg("hello");
Run Code Online (Sandbox Code Playgroud)
我的问题是:情况1或情况2是更好的方法吗?WaitForInputIdle(什么是输入和空闲的东西?)是什么意思?
我想Exception在非托管C程序集中保留指向托管对象的指针.
我尝试了很多方法.这是我发现的唯一通过我的初步测试的人.
有没有更好的办法?
我真正想做的是处理ExceptionWrapper构造函数和析构函数中的alloc和free方法,但是struct不能有构造函数或析构函数.
编辑:回复:为什么我想这样:
我的C结构有一个函数指针,该指针由一个托管委托作为非托管函数指针封送.受管代理使用外部设备执行一些复杂的测量,在这些测量期间可能会出现异常.我想跟踪发生的最后一个及其堆栈跟踪.现在,我只保存异常消息.
我应该指出托管委托不知道它与C DLL交互.
public class MyClass {
private IntPtr _LastErrorPtr;
private struct ExceptionWrapper
{
public Exception Exception { get; set; }
}
public Exception LastError
{
get
{
if (_LastErrorPtr == IntPtr.Zero) return null;
var wrapper = (ExceptionWrapper)Marshal.PtrToStructure(_LastErrorPtr, typeof(ExceptionWrapper));
return wrapper.Exception;
}
set
{
if (_LastErrorPtr == IntPtr.Zero)
{
_LastErrorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ExceptionWrapper)));
if (_LastErrorPtr == IntPtr.Zero) throw new Exception();
}
var wrapper = new ExceptionWrapper();
wrapper.Exception = value;
Marshal.StructureToPtr(wrapper, _LastErrorPtr, true); …Run Code Online (Sandbox Code Playgroud) 看到这个小提琴:http://jsfiddle.net/BxvVp/11/
我创建了一个视图模型,它具有一个用div页面上的一些隐藏内容替换内容的功能.一旦完成,text绑定似乎被处理,但click绑定不是.
难道我做错了什么?
HTML:
<h4>Clicking the anchor created by clicking 'Summarize' should cause an alert, but doesn't.</h4>
<a href="#" data-bind="click: summarize">Summarize</a>
<div id="plot1"></div>
<div id="summary1" style="display:none;"> <a data-bind="text: 'anchor-text-replaced', click: function(data, event) { alert('anchor clicked!'); }" href="#">anchor-text</a>
</div>
<hr />
<h4>Clicking this anchor causes the alert as exptected.</h4>
<div id="plot2"></div>
<div id="summary2">
<a data-bind="text: 'anchor-text-replaced', click: function(data, event) { alert('anchor clicked!'); }" href="#">anchor-text</a>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var ViewModel = function () { …Run Code Online (Sandbox Code Playgroud)