小编svi*_*ick的帖子

奥尔良的工作分配

在Microsoft Orleans中,我尝试使用以下代码实现类似可用工作的列表:

        public Task<WorkResponse> PerformWork(WorkRequest request)
    {
        Console.WriteLine("Performing work for id: {0}", request.Param1);
        Thread.Sleep(TimeSpan.FromSeconds(10));                       

        var result = Task.FromResult(new WorkResponse(request.Param1, request.Param2, request.Param3));
        Console.WriteLine("Completed work for id: {0}", request.Param1);

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

但是,如果我使用像这样的代码启动许多任务,那么事情就不会正常.

                _work
                .ToList()
                .AsParallel()                    
                .ForAll(x =>
                {        
                    Console.WriteLine("Requesting work for id: {0}", x.Key);
                    var worker = GrainFactory.GetGrain<IWork>(x.Key);
                    var response = worker.PerformWork(x.Value);

                    Console.WriteLine("Response for work id: {0}", x.Key);
                });
Run Code Online (Sandbox Code Playgroud)

但是,如果另一个节点加入群集,则工作似乎永远不会移动到新节点.仅在该新节点上处理新计划的工作.

似乎如果奥尔良队列中有一堆额外的工作,那么新节点就会加入群集.

c# distributed-computing cluster-computing orleans

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

HttpContext.Current在等待调用后在异步中为null

HttpContext.Current在等待调用后在异步中为null。

这是我的代码:

if (!string.IsNullOrEmpty(securityGroupName))
{
    // To remove the domain name from the security group name.
    string securityGroupDisplayName = securityGroupName.Split('\\')[1];
    string serviceSecurityGroupId = await this.graphApiClient.GetGroupIdAsync(securityGroupDisplayName).ConfigureAwait(false);

    if (!string.IsNullOrEmpty(serviceSecurityGroupId))
    {
        Task securityGroupRoleAddTask = this.CheckMembershipAndAddRole(serviceSecurityGroupId, userId, securityGroupName);
        Task flightAdminRoleAddTask = this.CheckMembershipAndAddRole(FlightAdminSecurityGroupId, userId, FlightAdminRoleName);
        Task.WaitAll(securityGroupRoleAddTask, flightAdminRoleAddTask);
    }
    else
    {
        LoggingUtilities.Logger.TraceInformation("Azure AD id does not exist for the security group: {0}.", securityGroupName);
        await this.CheckMembershipAndAddRole(FlightAdminSecurityGroupId, userId, FlightAdminRoleName).ConfigureAwait(false);
    }
}
else
{
    LoggingUtilities.Logger.TraceInformation("Security group name is not valid, checking for flight admin role for the user: {0}.", …
Run Code Online (Sandbox Code Playgroud)

c# httpcontext async-await asp.net-web-api

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

实现文件中未正确理解签名文件中的列表声明

我有以下签名文件F.fsi:

module M =

    type T1 = A | B

    type T2 =
        | F
        | G
        static member x1 : list<T1>
        static member x2 : list<T1>
Run Code Online (Sandbox Code Playgroud)

在我的实现文件中,F.fs我有以下内容:

module M =

    type T1 = A | B

    type T2 =
        | F
        | G
        static member x1 = [T1.A; T1.B]
        static member x2 = [] // LINE MARKER 1; ERROR OCCURS HERE
Run Code Online (Sandbox Code Playgroud)

Visual Studio x2使用以下错误消息对行的定义进行红线处理:

模块'M'包含static member M.T2.x2 : obj list但其签名指定static member …

f# types

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

在 C# Interactive 中取消转义字符串

在 VS 14 中,如果我输入(在 C# 交互窗口中)例如Environment.CurrentDirectory它说"C:\\Users\\some.username". 我怎样才能在"C:\Users\some.username"不手动删除字符的情况下获得呢?

c# roslyn c#-interactive

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

GetAsync:不返回HttpResponseMessage

应用程序应该从LoginUser()接收httpresponsemessage但它没有响应.

    private void button1_Click(object sender, EventArgs e)
    {
        if (LoginUser(tUser.Text, Password.Text).Result.IsSuccessStatusCode)
        {
            Notifier.Notify("Successfully logged in.. Please wait!");

        }
        else
        {
            Notifier.Notify("Please check your Credential..");
        }            
    }
Run Code Online (Sandbox Code Playgroud)
    public async Task<HttpResponseMessage> LoginUser(string userid, string password)
    {
        string URI = "http://api.danubeco.com/api/userapps/authenticate";

        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("c291cmF2OmtheWFs");

            using (var response = await client.GetAsync(String.Format("{0}/{1}/{2}", URI, userid, password)))
            {
                return response;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

请帮忙!

c# asynchronous async-await webapi2 httpresponsemessage

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

异步将WPF可视化呈现为位图

我看到WinRT RenderTargetBitmap能够通过"RenderAsync(visual);"异步呈现Visual.方法.不幸的是.net RendertargetBitmap 没有RenderAsync方法..net RenderTargetBitmap是否有任何变通方法或扩展,以允许WPF视觉效果的异步呈现?提前感谢您的帮助!

c# wpf asynchronous rendertargetbitmap async-await

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

WebMethod 异步结果显示对象

我正在尝试使用 async 返回结果,但我希望它返回整个对象而不是返回数据

[System.Web.Services.WebMethod(BufferResponse=false)]
public static async Task<bool> getLogin(string username, string password)
{
    Login login = new Login();
    Task<bool> loginVerify = login.verifyLogin(username,password);
    await loginVerify;
    return loginVerify.Result;
}

public class Login
{
    public async Task<bool> verifyLogin(string username, string password)
    {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

Firefox Firebug 的结果显示:

{"d":{"Result":true,"Id":2,"Exception":null,"Status":5,"IsCanceled":false,"IsCompleted":true,"CreationOptions":0,"AsyncState":null,"IsFaulted":false}}
Run Code Online (Sandbox Code Playgroud)

为什么不只是显示结果?

我试过跑步

public static async Task<bool> getLogin(string username, string password)
{
    Login login = new Login();
    Task<bool> loginVerify = login.verifyLogin(username,password);
    await loginVerify;
    return false;
}
Run Code Online (Sandbox Code Playgroud)

但是萤火虫报告是相同的,只是它在 json 中说 Result false

{"d":{"Result":false,"Id":2,"Exception":null,"Status":5,"IsCanceled":false,"IsCompleted":true,"CreationOptions":0,"AsyncState":null,"IsFaulted":false}}
Run Code Online (Sandbox Code Playgroud)

所以我的问题是为什么它显示整个对象而不是结果?

c# jquery webmethod async-await

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

缺少对装配的参考

我正在尝试创建一个套接字服务器,我遇到的问题我不知道如何解决.

这是我用于我的project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "vtortola.WebSocketListener": "2.2.0.2"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "net45"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我有这个基本脚本Server.cs:

using System.Net;
using vtortola.WebSockets;

public class Server {

    public static void Main(string[] args){

        var server = new WebSocketListener(new IPEndPoint(IPAddress.Any, 8006));
        var rfc = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(server);
        server.Standards.RegisterStandard(rfc);
        server.Start();

    }

}
Run Code Online (Sandbox Code Playgroud)

当我运行以下命令时:

master@ubuntu:~/Documents/Chat$ dotnet run
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

项目聊天(.NETCoreApp,Version = v1.0)将被编译,因为缺少预期的输出
编译.NETCoreApp的聊天,版本= v1.0
/usr/share/dotnet/dotnet compile-csc @/home/master/Documents/Chat/obj/Debug/netcoreapp1.0/dotnet-compile.rsp返回退出代码1
/home/master/Documents/Chat/Server.cs(8,26):错误CS0012:类型'IPEndPoint'在程序集中定义没有引用.您必须添加对程序集'System,Version = …

c# .net-core

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

如何在DynamicMethod Emit中表示typeof(Int32&)类型

我有以下代码:

    delegate void RefAction(ref Int32 i);// use ref keyword
    static RefAction CreateRefGenerator(){
        // How to represent typeof(Int32&)type in here??
        Type[] types ={ typeof(Int32)};
        var dm = new DynamicMethod("RefAction"+Guid.NewGuid().ToString(), null, types, true);
        var il = dm.GetILGenerator();
        il.Emit(OpCodes.Nop);
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Ldc_I4_S,10);
        il.Emit(OpCodes.Stind_I4);
        il.Emit(OpCodes.Ret);

        return (RefAction)dm.CreateDelegate(typeof(RefAction));
    }
Run Code Online (Sandbox Code Playgroud)

运行后,得到以下错误:

因为其签名或安全透明性与委托类型的签名或安全透明性不兼容.

以下正常工作:

  static RefAction CreateRefGenerator(){
        Type[] types = { typeof(Int32).MakeByRefType() };
        ...
  }
Run Code Online (Sandbox Code Playgroud)

c# cil dynamicmethod emit

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

取消使用异步函数创建的可观察对象

我是 rx 的新手,并且一直在使用 dot net 中的反应式扩展来处理一些网络代码。我的问题是,当我通过我提供的令牌触发取消时,我使用异步函数创建的 tcpClients 的 observable 没有像我预期的那样完成。这是我遇到问题的代码的简化版本:

public static class ListenerExtensions
{
    public static IObservable<TcpClient> ToListenerObservable(
        this IPEndPoint endpoint,
        int backlog)
    {
        return new TcpListener(endpoint).ToListenerObservable(backlog);
    }

    public static IObservable<TcpClient> ToListenerObservable(
        this TcpListener listener,
        int backlog)
    {
        return Observable.Create<TcpClient>(async (observer, token) => 
        {
            listener.Start(backlog);

            try
            {
                while (!token.IsCancellationRequested)
                    observer.OnNext(await Task.Run(() => listener.AcceptTcpClientAsync(), token));
                //This never prints and onCompleted is never called.
                Console.WriteLine("Completing..");
                observer.OnCompleted();
            }
            catch (System.Exception error)
            {
                observer.OnError(error);   
            }
            finally
            {
                //This is never executed and my …
Run Code Online (Sandbox Code Playgroud)

c# task system.reactive async-await .net-core

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