小编Par*_*and的帖子

为每个GeckoFx实例使用不同的代理

我正在使用Geckfx18.0和xulrunner18.01.由于Geckofx与其他实例共享cookie和用户首选项,因此我尝试创建一个新的配置文件目录,使它们具有唯一的设置,但似乎没有用.这是我的代码.我的代码有问题吗?

String profileDir = port.ToString();
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Path.Combine("Geckofx", profileDir));
this.Text = directory.ToString();

if (!Directory.Exists(directory))
    Directory.CreateDirectory(directory);

Gecko.Xpcom.ProfileDirectory = directory;
GeckoPreferences.User["network.proxy.type"] = 1;
GeckoPreferences.User["network.proxy.socks"] = "127.0.0.1";
GeckoPreferences.User["network.proxy.socks_port"] = port;
GeckoPreferences.User["network.proxy.socks_version"] = 5;
GeckoPreferences.User["general.useragent.override"] = ua;
Run Code Online (Sandbox Code Playgroud)

c# gecko geckofx

10
推荐指数
1
解决办法
1229
查看次数

在指定的时间段后停止方法

我正在从Active Directory中获取的PC列表上运行并行操作.我正在使用此方法来检查PC状态,例如计算机是否在线,或者是否存在特定目录.然而,由于这些操作的性质,有时是缓慢的操作,我想包括超时,以便我的应用程序可以继续运行.

public static T MethodTimeout<T>(Func<T> f, int timeout, out bool completed)
{
    T result = default(T);
    var thread = new Thread(() => result = F());
    thread.Start();
    Completed = thread.Join(Timeout);
    if (!Completed) thread.Abort();
    return result;
}
Run Code Online (Sandbox Code Playgroud)

这在很大程度上起作用,但是处理使用似乎有点飙升,并且在少数情况下我遇到了Out of Memory异常.所以,我改变了使用任务的方法,希望ThreadPool能消除上述问题:

public static T MethodTimeout<T>(Func<T> f, int timeout, out bool completed)
{
    T result = default(T);

    var timedTask = Task.Factory.StartNew(() => result = F());
    Completed = timedTask.Wait(Timeout);

    return result;
}
Run Code Online (Sandbox Code Playgroud)

但是,我有一种感觉,我只是填补了ThreadPool等待这些可能很长的任务完成的进程.由于我将任务的函数作为参数传递,因此我没有看到使用取消令牌的方法.但是,我对这些课程的经验非常有限,我可能会遗漏一些优秀的技巧.

以下是我一直使用上述方法的方法:

bool isReachable; // Check if the …
Run Code Online (Sandbox Code Playgroud)

c# multithreading active-directory task-parallel-library c#-4.0

8
推荐指数
2
解决办法
3634
查看次数

使EF core“点赞”功能动态表达

我编写了一些代码来制作动态表达式来过滤我的分页。我正在尝试制作 EF Core 内置函数的动态表达式以进行搜索 ( EF.Functions.Like)。

我尝试过像bottom这样的方法,但它是一个扩展方法,调用该方法时不使用第一个参数。我不知道如何遵循==> Ef => Function => Like的方式。
该方法应该像这样使用=>Ef.Functions.Like("Property to search", "%Some Pattern")

var likeMethod = typeof(DbFunctionsExtensions)
                        .GetMethods()
                        .Where(p => p.Name == "Like")
                        .First();
string pattern = $"%{finalConstant}%"; 

ConstantExpression likeConstant = Expression.Constant(pattern,typeof(string));

// the member expression is the property expression for example p.Name
var likeMethodCall = Expression.Call(method: likeMethod, arguments: new[] { memberExpression, likeConstant });

var searchLambda = Expression.Lambda<Func<T, bool>>(likeMethodCall, parameter);
query = query.Where(searchLambda);
Run Code Online (Sandbox Code Playgroud)

但它抛出异常说

为调用方法“Boolean Like(Microsoft.EntityFrameworkCore.DbFunctions, System.String, System.String)”提供的参数数量不正确\r\n参数名称: 方法

c# .net-core asp.net-core-webapi asp.net-core-2.0 ef-core-2.0

8
推荐指数
2
解决办法
5619
查看次数

C#中的字节溢出概念

我已经开始学习C#并且需要清除一些关于溢出概念的混淆.我们知道如果超过任何数据类型的限制,C#只返回0.

例如:字节b = 255; 如果我们将b的值增加1,那么b的值将为零.对于下面的代码,我输出为256.

 using System;
 namespace HelloWorld{
     class program{
          static void Main(){
                  byte b = 255;
                  Console.WriteLine(b+1);
           }
       }
  }
Run Code Online (Sandbox Code Playgroud)

而不是0,我输出为256,这超出了字节类型b的限制.这怎么可能 ?.

using System;
namespace HelloWorld{
class program{
    static void Main(){
        byte b = 255;
        b = b+1
        Console.WriteLine(b);
    }
}
Run Code Online (Sandbox Code Playgroud)

对于上面的代码我得到编译错误即错误CS0266:不能隐式转换类型int' to字节'.存在显式转换(您是否错过了演员?)

救命 !!!!

.net c#

3
推荐指数
1
解决办法
294
查看次数

从Dapper / PostgreSQL返回插入的项目的UUID

我的ASP.Net Core 2.1 Web API项目中有一个模型对象,如下所示:

public class Tenant
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

并且正在像这样在postgres中执行插入:

public async Task<int> CreateItem(Tenant item)
{
    return await db.ExecuteAsync($@"INSERT INTO tenants (Name) VALUES (@Name)", item);
}
Run Code Online (Sandbox Code Playgroud)

我需要Guid来驱动后续逻辑。它返回受影响的行(1)。我的研究表明,有一些技巧可用于获取自动增量ID(例如使用“ MAX”等)。

有没有办法做到这一点,最好是通过dapper?还是我需要退回到ADO.Net?

c# postgresql dapper asp.net-core

3
推荐指数
1
解决办法
937
查看次数

如何检查 SQL 记录是否按特定顺序排列

我无法弄清楚如何检查表上的记录是否按特定顺序排列。简化的表设计本质上是这样的:

+------------+----------------+--------+
| ID (GUID)  |   StartDate    | NumCol |
+------------+----------------+--------+
| CEE8C17... | 8/17/2019 3:11 |     22 |
| BB22001... | 8/17/2019 3:33 |     21 |
| 4D40B12... | 8/17/2019 3:47 |     21 |
| 3655125... | 8/17/2019 4:06 |     20 |
| 3456CD1... | 8/17/2019 4:22 |     20 |
| 38BAF92... | 8/17/2019 4:40 |     19 |
| E60CBE8... | 8/17/2019 5:09 |     19 |
| 5F2756B... | 8/17/2019 5:24 |     18 |
+------------+----------------+--------+
Run Code Online (Sandbox Code Playgroud)

ID列是非连续的 GUID。 …

sql-server sql-server-ce

1
推荐指数
1
解决办法
6407
查看次数