小编koo*_*e98的帖子

如何在ASP.NET Web API中执行异步"即发即忘"操作

所以,我有这个Web API动作,它执行一个异步函数.

public void Post([FromBody]InsertRequest request)
{
    InsertPostCommand.Execute(request);
    DoAsync();
}

private async void DoAsync()
{
    await Task.Run(() =>
    {
        //do async stuff here
    });
}
Run Code Online (Sandbox Code Playgroud)

我实际上希望控制器操作在执行异步操作时返回到客户端.

我这样做了,因此我得到一个例外:

System.InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.
Run Code Online (Sandbox Code Playgroud)

我怎么能实现这个呢?

谢谢

c# asp.net asynchronous asp.net-web-api

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

使用 MSBuild 将多个 JSON 文件合并为一个 JSON 文件

在我的 ASP.NET MVC Web 项目中,我有许多 JSON 文件。

File1.json

{
   "manage_employees_section_title": 
    {
        "value": "Manage employees",
        "description": "The mange employees section title"
    }
}
Run Code Online (Sandbox Code Playgroud)

File2.json

{
   "manage_operations_section_title": 
    {
        "value": "Manage operations
        "description": "The mange operations section title"
    }
}
Run Code Online (Sandbox Code Playgroud)

作为构建过程的一部分,我需要将所有内容JSONs合并到一个文件中。

我已经这样使用MSBuild了。

<Target Name="ConcatenateJsFiles">
   <ItemGroup>
     <ConcatFiles Include="Application\**\resource-content*.json"/>
   </ItemGroup>

   <ReadLinesFromFile File="%(ConcatFiles.Identity)">
     <Output TaskParameter="Lines" ItemName="ConcatLines"/>
   </ReadLinesFromFile>

   <WriteLinesToFile File="Infrastructure\Content\Store\ContentStore.json" Lines="@(ConcatLines)" Overwrite="true" />
</Target>
Run Code Online (Sandbox Code Playgroud)

这就是我得到的......

Concat.json

//What I got
{
   "manage_employees_section_title": 
    {
        "value": "Manage employees",
        "description": "The mange employees section title"
    }
}
{
   "manage_operations_section_title": …
Run Code Online (Sandbox Code Playgroud)

msbuild json build-process csproj visual-studio

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

实体框架插入具有相关对象的对象

我是Entity Framework的新手,我需要将一个Comment具有相关FK对象的对象User插入到数据库中.

    public Class Comment
    {
        public int CommentID { get; set; }
        public string CommentContent { get; set; }
        public virtual User User { get; set; }
        public virtual DateTime CommentCreationTime { get; set; }
    }

public class User
{      

    public int UserID { get; set; }
    public string UserName { get; set; }
    public string UserPassword { get; set; }

    public string UserImageUrl{get; set;}
    public DateTime UserCreationDate { get; set; }

    public virtual List<Comment> …
Run Code Online (Sandbox Code Playgroud)

entity-framework-4 c#-4.0

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

MVC Razor助手在当前上下文中不存在

我在我的MVC4 Web应用程序中创建了一个自定义剃刀助手,我需要在所有视图中使用它.

在我的所有视图页面中,我似乎无法使用自定义帮助程序.VS2012不只是看到它.

我该如何解决这个问题?

编辑:它实际上在我运行页面时有效,它只是VS看不到它.

这是我的帮助程序,它位于我的AppCode文件夹中的Helpers.cshtml中.

@helper TextBox(string title, string id, string placeholder, bool required){    
<ul>
    <li>
        <label for="@id">@title</label>
    </li>
    <li>
        <input type="text" name="this" class="@if (@required) {<text>required</text>}" minlength="2" id="@id" placeholder="@placeholder" />
    </li>
</ul>
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc razor visual-studio-2012

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

MSBuild:将自定义资源文件包含为嵌入资源

我在构建时使用MSBuild动态生成资源文件,但为了能够在运行时从该资源文件中读取,我需要它作为嵌入式资源.

我已经到处查看如何在.csproj嵌入式资源中标记文件,我甚至尝试过无效.

<ItemGroup>
  <Content Include="Infrastructure\Content\Store\content_store_en.json" />
  <EmbeddedResource Include="Infrastructure\Content\Store\content_store_en.json">
  </EmbeddedResource>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

有什么办法可以实现吗?

msbuild csproj visual-studio

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

Union,Join或GroupBy

我有程序从各种来源拉取数据给我3个非常类似的表.

Metric          | Tickets   |Band
______________________________________
Acknowledgement | 45        | New
Acknowledgement | 23        | Within
Acknowledgement | 16        | Near
Acknowledgement | 2         | Very Near
Run Code Online (Sandbox Code Playgroud)

Metric     | Tickets   |Band
___________________________________
Escalation | 10        | New
Escalation | 43        | Within
Escalation | 81        | Near
Escalation | 6         | Very Near
Run Code Online (Sandbox Code Playgroud)

Metric| Tickets   |Band
___________________________________
Fixed | 34        | New
Fixed | 52        | Within
Fixed | 36        | Near
Fixed | 4         | Very Near …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server sql-server-2008

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