我正在使用Windows服务中的CreateProcessAsUser(我们可以继续讨论主题,并假设我有充分的理由这样做).与其他人在这里问的问题相反,我在我的活动终端会话(会话1)中获得了一个窗口,而不是与服务(会话0)相同的会话 - 这是不可取的.
我挪用了斯科特艾伦的代码 ; 并想出了以下内容.值得注意的变化是"恢复自我","CREATE_NO_WINDOW"和命令行args支持.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Security.Principal;
using System.ComponentModel;
using System.IO;
namespace SourceCode.Runtime.ChildProcessService
{
[SuppressUnmanagedCodeSecurity]
class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct STARTUPINFO
{
public Int32 cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public Int32 dwX;
public Int32 dwY;
public Int32 dwXSize;
public Int32 dwXCountChars;
public Int32 dwYCountChars;
public Int32 dwFillAttribute;
public Int32 dwFlags;
public Int16 wShowWindow;
public Int16 cbReserved2; …Run Code Online (Sandbox Code Playgroud) ASP.NET在请求路径中"正常化"反斜杠以转发斜杠,我需要它们作为反斜杠(它用于在数据库中执行查找).我不介意如果没有转义,转义为正斜面的转义是不是这个问题.
config.Routes.MapHttpRoute(
name: "TransactionsApi",
routeTemplate: "api/transactions/{*transaction}",
defaults: new { controller = "transactions", transaction = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
请注意,我已设置事务以匹配路径的其余部分.
我尝试了以下URL(来自浏览器和Fiddler):
api/transactions/mscorlib.pdb\DFA83312EAB84F67BD225058B188F22B1\mscorlib.pdbapi/transactions/mscorlib.pdb\\DFA83312EAB84F67BD225058B188F22B1\\mscorlib.pdbapi/transactions/mscorlib.pdb%5CDFA83312EAB84F67BD225058B188F22B1%5Cmscorlib.pdbapi/transactions/mscorlib.pdb%5C%5CDFA83312EAB84F67BD225058B188F22B1%5C%5Cmscorlib.pdb当他们点击我的Web API方法时,他们就是全部mscorlib.pdb/DFA83312EAB84F67BD225058B188F22B1/mscorlib.pdb.我检查了当前的情况HttpContext,看起来ASP.NET正在进行这种规范化(而不是MVC4).
可能的解决方案:
{*transaction}部分,如果它包含一个反斜杠.不是真正的地址栏hackable有关如何让ASP.NET 不进行此规范化的任何想法?
尝试在VS2015中运行使用混合模式程序集的单元测试时,测试无法使用常规消息执行:
System.IO.FileLoadException:混合模式程序集是针对运行时的版本"v2.0.50727"构建的,如果没有其他配置信息,则无法在4.0运行时中加载.
创建app.config并添加useLegacyV2RuntimeActivationPolicy到它没有任何效果 - 好像这个配置无法改变.
以前在VS2013中没有手动步骤.
以下面的课程为例.
public class A
{
// ...
void Foo(S myStruct){...}
}
public class B
{
public A test;
// ...
void Bar()
{
S myStruct = new S();
test.Foo(myStruct);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我希望方法调用test.Foo(myStruct)是一个异步调用('fire-and-forget').条形方法需要尽快返回.代理,BeginInvoke,EndInvoke,ThreadPool等文档不能帮助我找到解决方案.
这是有效的解决方案吗?
// Is using the `EndInvoke` method as the callback delegate valid?
foo.BeginInvoke(myStruct, foo.EndInvoke, null);
Run Code Online (Sandbox Code Playgroud) 我优化了一个扩展方法来比较两个流的相等性(逐字节) - 知道这是一个热门的方法,我试图尽可能地优化它(流可以达到数兆字节的长度).我基本上想出了以下方法:
[StructLayout(LayoutKind.Explicit)]
struct Converter
{
[FieldOffset(0)]
public Byte[] Byte;
[FieldOffset(0)]
public UInt64[] UInt64;
}
/// <summary>
/// Compares two streams for byte-by-byte equality.
/// </summary>
/// <param name="target">The target stream.</param>
/// <param name="compareTo">The stream to compare the target to.</param>
/// <returns>A value indicating whether the two streams are identical.</returns>
public static bool CompareBytes(this Stream target, Stream compareTo)
{
if (target == null && compareTo == null)
return true;
if (target == null || compareTo == null)
return false; …Run Code Online (Sandbox Code Playgroud) 我试图通过使用以下内容向我的单元测试项目公开一些内部:
[assembly: InternalsVisibleTo("MyTest")]
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误:
错误1朋友程序集引用MyTest'无效.强名称签名程序集必须在其InternalsVisibleTo声明中指定公钥..../MyClass.cs ...
当我手动分配PublicTokenKey时:
[assembly: InternalsVisibleTo("MyTest, PublicKeyToken=XxxxxYysakf")]
Run Code Online (Sandbox Code Playgroud)
解决方案构建没有任何错误.
那么,为我的Test项目分配公钥的最佳和最安全的方法是什么?
合并2组排序值的最快方法是什么?速度(大O)在这里很重要; 不清楚 - 假设这已经完成了数百万次.
假设你不知道值的类型或范围,但有一个高效IComparer<T>和/或IEqualityComparer<T>.
给出以下数字:
var la = new int[] { 1, 2, 4, 5, 9 };
var ra = new int[] { 3, 4, 5, 6, 6, 7, 8 };
Run Code Online (Sandbox Code Playgroud)
我期待1,2,3,4,5,6,7,8,9.以下存根可用于测试代码:
static void Main(string[] args)
{
var la = new int[] { 1, 2, 4, 5, 9 };
var ra = new int[] { 3, 4, 5, 6, 6, 7, 8 };
foreach (var item in UnionSorted(la, ra, Int32Comparer.Default))
{
Console.Write("{0}, ", item);
} …Run Code Online (Sandbox Code Playgroud) 如何使用C#以字符串格式获取本地系统的DateTime格式?
例如:dd/MM/yyyy或MM/dd/YYYY
c# ×8
.net ×3
unit-testing ×2
action ×1
asp.net ×1
asynchronous ×1
conditional ×1
datetime ×1
delegates ×1
logic ×1
mstest ×1
pinvoke ×1
sortedset ×1
union ×1