小编And*_* A.的帖子

这是线程安全吗?

只是检查...... _count正在安全访问,对吗?

两个方法都由多个线程访问.

private int _count;

public void CheckForWork() {
    if (_count >= MAXIMUM) return;
    Interlocked.Increment(ref _count);
    Task t = Task.Run(() => Work());
    t.ContinueWith(CompletedWorkHandler);
}

public void CompletedWorkHandler(Task completedTask) {
    Interlocked.Decrement(ref _count);
    // Handle errors, etc...
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading interlocked thread-safety

41
推荐指数
4
解决办法
3413
查看次数

ASP.NET长时间运行的任务.线程正在中止异常

ASP.NET 3.5 webapp必须启动几个需要几个小时才能完成的任务.出于显而易见的原因,启动这些任务的页面不能等待它们完成,也不会有任何人想要等待那么长时间才能获得响应,因此任务必须是异步的.

有一个Helper类来处理所有这些长时间运行的任务.计划和执行这些任务的主要方法目前如下:

public static bool ScheduleTask(TaskDescriptor task, Action action)
{
    bool notAlreadyRunning = TasksAsync.TryAdd(task);
    if (notAlreadyRunning)
    {
        Thread worker = null;
        worker = new Thread(() => 
        {
            try { action(); }
            catch(Exception e)
            {
                Log.LogException(e, "Worker");
            }
            TasksAsync.RemoveTask(task);
            workers.Remove(worker);
        });
        workers.Add(worker);
        worker.Start();
    }
    return notAlreadyRunning;
}
Run Code Online (Sandbox Code Playgroud)

在早期的实现中,我们使用了这种ThreadPool.QueueUserWorkItem方法,但结果总是相同的:在aprox之后.20-30分钟一个线程被中止异常被抛出.

有谁知道为什么会这样?或者如何预防?

更多信息:

  • IIS标准配置.
  • 任务可以是任何内容,查询数据库和/或IO操作等.

更新:决定

谢谢大家的回复.现在我不知道哪个问题要标记为答案.所有这些都是有效的,并且可以解决这个问题.将等待今天并以最高票数回答答案,如果是平局,我将选择第一个显示的答案,通常它们按最相关的顺序排序.

对于任何想要知道我选择的解决方案的人,再次由于时间限制,是改变IIS回收配置,但我认为是理想的解决方案,基于我的研究,当然下面的答案,是创建一个"工作服务"并使用ASP.NET应用程序和新的"工作服务"之间的通信解决方案来协调要完成的长时间工作.

c# asp.net asynchronous

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

ObjectDataSource删除问题

环境:asp.net框架2.0

我遇到了自定义对象的Delete方法问题ObjectDataSource.的Select,InsertUpdate方法的正常工作.

这是类的代码:

public class Car
{
    public string ID {get; set;}//I know this is 3.0+ syntax.
    public string Description {get; set;}//I know this is 3.0+ syntax.

    public bool Equals(Car other)
    {
        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;
        return other.ID == ID;
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        return obj.GetType() == typeof (Car) && Equals((Car) …
Run Code Online (Sandbox Code Playgroud)

asp.net ado.net objectdatasource

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

从多个表中删除同一组值

我不想一遍又一遍地为所有表重复相同的子查询.

例:

begin
    -- where subquery is quite complex and returns thousands of records of a single ID column
    delete from t1 where exists ( select 1 from subquery where t1.ID = subquery.ID );
    delete from t2 where exists ( select 1 from subquery where t2.ID = subquery.ID );
    delete from t3 where exists ( select 1 from subquery where t3.ID = subquery.ID );
end;
/
Run Code Online (Sandbox Code Playgroud)

我发现的另一种选择是:

declare
  type id_table_type is table of table.column%type index by PLS_INTEGER
  ids id_table_type;
begin …
Run Code Online (Sandbox Code Playgroud)

oracle oracle11g

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

如何以编程方式设置报表查看器的报表语言?

你们中有人知道是否可能以及如何以编程方式设置报表查看器的报表语言吗?

例如,这样的事情:

var reportviewer = new ReportViewer();
reportViewer.LocalReport.Language = CultureInfo.CurrentUICulture;
Run Code Online (Sandbox Code Playgroud)

或者更具体地说,是否可以将报告语言设置为自定义区域性以及如何设置?

globalization reportviewer

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

为什么excel仍然开放?

可能重复:
如何在C#中正确清理Excel互操作对象

我用这个函数计算一些数据的线性趋势:

private string Trend(object conocido_y, object conocido_x, object nueva_matriz_x)
{
    string result = String.Empty;
    try {
        Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
        result = ((Array)xlApp.WorksheetFunction.Trend(conocido_y, conocido_x, nueva_matriz_x, true)).GetValue(1).ToString();
        xlApp.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
        xlApp = null;
    }
    catch (System.Runtime.InteropServices.COMException ex) {
        DError.ReportarError(ex, false);
    }
    catch (Exception ex) {
        DError.ReportarError(ex);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

结果很好,但excel应用程序没有关闭,如果我打开任务管理器进程仍在运行,为什么?

c# asp.net excel interop

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

如何将文件另存为其他用户

是否可以作为登录用户运行Windows窗体应用程序,但是使用不同的用户凭据使应用程序保存文件?

我知道以下是不正确的,但我的意思是这样的:

var userWithPrivileges = new NetworkCredential(userName, password);
File.Copy(sourceFileName, destFileName, overwrite: true, userWithPrivileges);
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

是否有 DataWeave 1.0“for”运算符?

我想创建与计数变量指定一样多的元素,例如:

有一个表格,其中包含有关支持的设备的信息

select port_count 
from equipment
where id=#[flowVars.equipmentId]
Run Code Online (Sandbox Code Playgroud)

我必须生成一条消息,让另一个不受我控制的系统解释和执行:

<dw:transform-message doc:name="Get value">
    <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
  "actions": {
    (for 1..flowVars.port_count map {
      "action": {
        "type": "add_port",
        "id": $$
      }
    })
  }
}]]></dw:set-payload>
</dw:transform-message>
Run Code Online (Sandbox Code Playgroud)

想要的结果:

{
  "actions": {
    "action": {
        "type": "add_port",
        "id": 1
    },
    "action": {
        "type": "add_port",
        "id": 2
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

mule dataweave

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