小编Joe*_*lty的帖子

进程有时在等待退出时挂起

我的进程在等待退出时挂起的原因可能是什么?

此代码必须启动 powershell 脚本,该脚本在内部执行许多操作,例如通过 MSBuild 开始重新编译代码,但问题可能是它生成了太多输出,并且即使在正确执行 power shell 脚本后,此代码在等待退出时也会卡住

这有点“奇怪”,因为有时这段代码运行良好,有时却卡住了。

代码挂在:

process.WaitForExit(ProcessTimeOutMiliseconds);

Powershell 脚本在 1-2 秒内执行,同时超时为 19 秒。

public static (bool Success, string Logs) ExecuteScript(string path, int ProcessTimeOutMiliseconds, params string[] args)
{
    StringBuilder output = new StringBuilder();
    StringBuilder error = new StringBuilder();

    using (var outputWaitHandle = new AutoResetEvent(false))
    using (var errorWaitHandle = new AutoResetEvent(false))
    {
        try
        {
            using (var process = new Process())
            {
                process.StartInfo = new ProcessStartInfo
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = "powershell.exe",
                    RedirectStandardOutput = true,
                    RedirectStandardError = …
Run Code Online (Sandbox Code Playgroud)

c#

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

Web 浏览器(Chromium/Firefox)在文件对话框后 1-2 秒内无响应

从文件对话框中选择文件并单击“确定”后,如何改进此代码以消除无响应/页面延迟?

我一直在测试大小约为 50-100 KB 的文件

function handleFileSelect(evt) {
  var files = evt.target.files; // FileList object

  // files is a FileList of File objects. List some properties.
  var output = [];
  for (var i = 0, f; f = files[i]; i++) {
    output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
      f.size, ' bytes, last modified: ',
      f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
      '</li>');
  }
  document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}

document.getElementById('files').addEventListener('change', handleFileSelect, false);
Run Code Online (Sandbox Code Playgroud)
<input type="file" id="files" name="files[]" multiple …
Run Code Online (Sandbox Code Playgroud)

html javascript

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

将 db 上下文注入 Hangfire Recurring 作业的正确方法是什么?

我正在使用 HangFire 在后台定期向用户发送电子邮件。

我正在从数据库中获取电子邮件地址,但我不确定是否将数据库上下文“注入”到负责正确发送电子邮件的服务中

这工作正常,有没有更好的方法来做到这一点?

public void Configure(IApplicationBuilder app, IHostingEnvironment env, Context context)
{
    (...)

    app.UseHangfireDashboard();
    app.UseHangfireServer(new BackgroundJobServerOptions
    {
        HeartbeatInterval = new System.TimeSpan(0, 0, 5),
        ServerCheckInterval = new System.TimeSpan(0, 0, 5),
        SchedulePollingInterval = new System.TimeSpan(0, 0, 5)
    });

    RecurringJob.AddOrUpdate(() => new MessageService(context).Send(), Cron.Daily);

    (...)
    app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
public class MessageService
{
    private Context ctx;

    public MessageService(Context c)
    {
        ctx = c;
    }

    public void Send()
    {
        var emails = ctx.Users.Select(x => x.Email).ToList();

        foreach (var email in emails)
        {
            sendEmail(email, "sample body"); …
Run Code Online (Sandbox Code Playgroud)

c# hangfire .net-core asp.net-core

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

托管在Linux上的Visual Studio远程调试应用程序 - 无法在特定进程中枚举CoreCLR的运行实例

我正在尝试远程调试在Linux上托管的应用程序

"Debian GNU/Linux 8(jessie)"

.NET命令行工具(2.1.500)

我通过SSH连接Visual Studio

我尝试了两种模式:

  • 适用于Unix的托管.NET Core

  • 原生(GDB)

项目已在Windows上编译

dotnet publish --configuration Release -r linux-x64
Run Code Online (Sandbox Code Playgroud)

并且

dotnet publish --configuration Debug -r linux-x64
Run Code Online (Sandbox Code Playgroud)

并且工作得非常好,但出于某种原因,我收到了:

适用于Unix的托管.NET Core:

无法附加到进程:无法枚举特定进程中正在运行的CoreCLR实例


如果这是相关的(可能不是,因为其他人使用Managed .NET Core for Unix)

Native(GDB): 无法启动调试.无法建立与GDB的连接.调试输出可能包含更多信息

调试信息:

Starting unix command: 'gdb --interpreter=mi'
bash: gdb: command not found
gdb --interpreter=mi exited with code 127.
Run Code Online (Sandbox Code Playgroud)

在Visual Studio中,进程列为:

Process: MyProjectName

Title: /home/deploy/app/MyProjectName StartUpArgument
Run Code Online (Sandbox Code Playgroud)

有人知道是什么原因引起的吗?

你可以在这里看到人们如何使用Raspberry Pi做到这一点:

https://youtu.be/ySzTCl-H10w?t=955

c# remote-debugging visual-studio .net-core

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

如何告诉编译器将wwwroot从一个项目复制到Tests proj?

假设我有以下项目结构:

- AppRunner
        | - Apprunner.csproj
        | - wwwroot


- Tests  
        | - Tests.csproj
        | - bin
                | - debug
                        | - netcoreapp2.1
                                        | - I want copy wwwroot here
Run Code Online (Sandbox Code Playgroud)

我想告诉编译器将wwwroot所有项目和文件夹复制到output folder of tests

但我希望它不仅在Windows上也可以在Linux上正常工作

我添加到Tests.csproj这:

<ItemGroup>
    <None Update="..\AppRunner\wwwroot\*">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

但这不是真的

c# .net-core dotnet-cli

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

Docker上的MSSQL立即退出

我正在尝试在Windows 10的Docker上设置MSSQL,但由于某种原因,它开始关闭了我的容器

我已经使用了几个月了,但是现在我不知道发生了什么

    C:\Users\user\
    ? docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

    C:\Users\user\
    ? docker login
    Authenticating with existing credentials...
    Login Succeeded

    C:\Users\user\
    ? docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>123' -p 1433:1433 --name sql -d mcr.microsoft.com/mssql/server:2017-latest
    337e5efb35f0bf4b465181a0f8be4851b12f353a3a8710ddf817d2f501e5fea

    C:\Users\user\
    ? docker ps -a
    CONTAINER ID        IMAGE                                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
    347q5effb3cf0        mcr.microsoft.com/mssql/server:2017-latest   "/opt/mssql/bin/sqls…"   3 seconds ago       Up 2 seconds        0.0.0.0:1433->1433/tcp   sql

    C:\Users\user\
    ? docker ps -a
    CONTAINER ID        IMAGE                                        COMMAND                  CREATED             STATUS                     PORTS               NAMES
    347q5effb3cf0        mcr.microsoft.com/mssql/server:2017-latest …
Run Code Online (Sandbox Code Playgroud)

sql-server

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

如何从不是从控制器派生的类返回 ActionResult(文件)?

我有两种下载文件方法,所以我想将实际命中磁盘的部分提取到某个帮助程序/服务类,但是我很难将该文件返回给控制器,然后返回给用户

如何从不是从Controller具有易于工作的方法的文件派生的类返回Mvc.ControllerBase.File

public (bool Success, string ErrorMessage, IActionResult File) TryDownloadFile(string FilePath, string FriendlyName)
{
    try
    {
        var bytes = File.ReadAllBytes(FilePath);

        if (FilePath.EndsWith(".pdf"))
        {
            return (true, "", new FileContentResult(bytes, "application/pdf"));
        }
        else
        {
            return (true, "", ControllerBase.File(bytes, "application/octet-stream", FriendlyName));
        }
    }
    catch (Exception ex)
    {
        return (false, ex.Message, null); 
    }
}
Run Code Online (Sandbox Code Playgroud)

错误是

非静态字段、方法或属性“ControllerBase.File(Stream, string, string)”需要对象引用

对于这一行:

return (true, "", ControllerBase.File(bytes, "application/octet-stream", FriendlyName));
Run Code Online (Sandbox Code Playgroud)

有没有可能实现这一目标?

c# asp.net-core-mvc asp.net-core

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

如何在本地创建 IConfiguration 的实例?

我想问一下如何创建 ASP.NET Core 配置的实例,这与我在知道该appsettings.json文件的Controller 的构造函数中需要它时创建的实例相同

喜欢 _config = ActivatorUtilities.CreateInstance<IConfiguration>(null);

System.InvalidOperationException: '找不到适合类型 'Microsoft.Extensions.Configuration.IConfiguration' 的构造函数。确保类型是具体的,并且为公共构造函数的所有参数注册了服务。

这是有道理的,因为它是接口,但是它在 Controller 的构造函数情况下是如何工作的呢?以及如何创建一个实例?

我正在使用 MS DI

谢谢

c# dependency-injection .net-core asp.net-core

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

远程调试 - .NET Core 调试器不支持 Windows PDB - 如何正确发布?

我正在 Windows 上的 .NET Core 2.1 中编写 ASP.NET Core APP,并在使用后将其部署到服务器上

dotnet publish --configuration Debug -r linux-x64 我无法通过远程调试器连接 SSH

因为:

WARNING: Could not load symbols for 'Common.dll'. '/home/dev/Common.pdb' is a Windows PDB. These are not supported by the cross-platform .NET Core debugger.

为什么会发生?以及我必须如何发布才能远程调试它?

c# deployment .net-core

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

NPOI - 加载 Excel 文件导致错误的本地标题签名:0xE011CFD0

有没有人知道可能导致此错误的原因

'错误的本地头签名:0xE011CFD0'

var path = @"C:\Excel.xls";

using (var fs = File.OpenRead(path))
{
    var wb = new XSSFWorkbook(fs);
}
Run Code Online (Sandbox Code Playgroud)

我使用:https : //github.com/dotnetcore/NPOI

c# excel npoi .net-core

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