我试图在任务上设置公寓状态但是看不到这样做的选项.有没有办法使用任务执行此操作?
for (int i = 0; i < zom.Count; i++)
{
Task t = Task.Factory.StartNew(zom[i].Process);
t.Wait();
}
Run Code Online (Sandbox Code Playgroud) 在我们的一个产品中,我们使用ODP.net托管驱动程序使用存储过程从Oracle数据库中检索数据.
每隔一段时间(大约每1000个查询)我们就会得到以下异常:
(ORA-12570: Network Session: Unexpected packet read error)
---> Oracle.ManagedDataAccess.Client.OracleException: ORA-12570: Network Session: Unexpected packet read error
---> OracleInternal.Network.NetworkException: ORA-12570: Network Session: Unexpected packet read error
---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: size
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
--- End of inner exception stack trace ---
at OracleInternal.Network.ReaderStream.ReadIt(OraBuf OB, Int32 len)
at OracleInternal.Network.ReaderStream.WaitForReset()
at OracleInternal.Network.OracleCommunication.Reset()
at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, …
Run Code Online (Sandbox Code Playgroud) 以下使用 Autofac 的代码的 NInject 等效项是什么:
var builder = new ContainerBuilder();
System.Reflection.Assembly assembly = ...;
builder.RegisterAssemblyTypes(assembly).AsClosedTypesOf(typeof(OpenGeneric<>))
.As<IAnInterface>();
var resolved = container.Resolve<IEnumerable<IAnInterface>>();
Run Code Online (Sandbox Code Playgroud) 到目前为止,我见过的所有webapi + odata示例都WebApiConfig.Register
使用以下内容构建模型:
...
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<AClass>("SetName");
...
IEdmModel model = modelBuilder.GetEdmModel();
Run Code Online (Sandbox Code Playgroud)
就我而言,我想动态构建modelBuilder.EntitySet<AClass>("SetName")
运行时使用的类,并在第一次执行对此实体集的请求时动态注册它们.
我读过这篇文章 ,当没有可用的后备CLR类型但仍然在服务启动期间构建模型时使用EdmEntityObject.
有没有办法在飞行中构建模型?
我有以下班级结构。类 A 从类 B 和 C 的构造函数中调用。
Class A
{
A()
}
Class B
{
B()
{
A();
}
}
Class C
{
C()
{
A();
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法知道对 A() 的调用是来自 B() 还是 C()?我不想在构造函数中传递任何对象。
我得到了一些复杂的代码,导致显示了一些数字。该代码仍在开发中,而不是最终的。现在,最终用户想了解数字的计算方式。
因此,举一个非常简单的例子:
var x = y + z; // x = 10 + 20
Display(x); // x will be 30
Run Code Online (Sandbox Code Playgroud)
但是我想要一个帮助字符串
"x = y(10) + z(20) = 30"
Run Code Online (Sandbox Code Playgroud)
这是一个非常简单的示例,典型地,我得到了像树结构这样的深层公式。
有没有人做过类似的事情并且有一些提示和技巧?
我试图创建自己的double类来重写+-*/
并创建一个字符串。但是代码变得非常难看。
public class Client
{
public string nome;
}
Client j, h, m, n;
j = h = m = n = new Client();
Client[] c= new Client[]{j,h,m,n};
int[] n = new int[c.Length];
for (int i = 0; i < c.Length; ++i)
{
n[i] =i;
c[i].nome = "Client"+i;
}
Run Code Online (Sandbox Code Playgroud)
在输出中n = 0,1,2,3
;
但在输出中 c = Client4,Client4,Client4,Client4
我不是编程的新生,但我无法弄清楚为什么它不会连接每一个值.我无法向自己解释.c[i]
它有,它应该工作.
有人能帮忙吗?
我正在深入阅读Jon Skeet的C#第二版,我想到了以下问题:
怎么样能够之间进行选择的编译器list.Sort(Comparison<T>)
,并list.Sort(MyComparison<T>)
在下面的例子:
// MyComparison has the same signature as Comparison<in T>
public delegate int MyComparison<in T>(T x, T y);
public class MyList<T> : List<T>
{
// Sort is like Sort(Comparison<T>) except it takes a MyComparison<T> in parameter
public int Sort(MyComparison<T> comparison)
{
Console.WriteLine("Sort MyComparison<T>");
return -1;
}
}
MyList<Product> list = new MyList<Product>();
list.Sort((product1, product2) => product1.Name.CompareTo(product2.Name));
// Equivalent to
list.Sort(new MyComparison<Product>((product1, product2) => product1.Name.CompareTo(product2.Name)));
// But not equivalent to...
list.Sort(new Comparison<Product>((product1, product2) => product1.Name.CompareTo(product2.Name))); …
Run Code Online (Sandbox Code Playgroud) 当我在我的机器上以释放模式执行以下代码时,具有非null目标的委托的执行总是比委托具有空目标时快(我希望它等效或更慢).
我真的不是在寻找微优化,但我想知道为什么会这样呢?
static void Main(string[] args)
{
// Warmup code
long durationWithTarget =
MeasureDuration(() => new DelegatePerformanceTester(withTarget: true).Run());
Console.WriteLine($"With target: {durationWithTarget}");
long durationWithoutTarget =
MeasureDuration(() => new DelegatePerformanceTester(withTarget: false).Run());
Console.WriteLine($"Without target: {durationWithoutTarget}");
}
/// <summary>
/// Measures the duration of an action.
/// </summary>
/// <param name="action">Action which duration has to be measured.</param>
/// <returns>The duration in milliseconds.</returns>
private static long MeasureDuration(Action action)
{
Stopwatch stopwatch = Stopwatch.StartNew();
action();
return stopwatch.ElapsedMilliseconds;
}
class DelegatePerformanceTester
{
public DelegatePerformanceTester(bool withTarget)
{
if …
Run Code Online (Sandbox Code Playgroud) 我想将一组回调函数绑定到C#中的GUI元素,每个函数使用不同的参数调用相同的处理函数.
拼写出来的方式
# Assign element #1 to widget
widget.Click += () => {ProcessClick(1) ;} ;
# Assign element #2 to widget
widget.Click += () => {ProcessClick(2) ;} ;
...
Run Code Online (Sandbox Code Playgroud)
似乎多余.然而,一个天真的循环
Widget widget ;
foreach (int i in new List<int>() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} )
{
# Assign element i to widget
widget.Click += () => {ProcessClick(i) ;} ;
}
Run Code Online (Sandbox Code Playgroud)
将无法工作,因为一旦调用任何回调,循环将过期,从而导致ProcessClick(9)
每个小部件的调用.
我觉得应该有一个简单的解决方案,但我被卡住了.
如何将回调函数绑定到GUI元素,每个GUI元素调用具有不同参数的函数而不将它们全部拼写出来?
目前我正在使用这个:
new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
DateTime.Now.Hour, DateTime.Now.Minute, 0)
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以直接将秒和毫秒设置为 0。