Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 确切地说,问题是什么,但是代码现在运行得非常愉快,没有任何修改。不幸的是,由于时间限制,我没有完全调查这个问题。 public override void Run() { Trace.TraceInformation("Foo.PushProces_C#_Azure_Azure Worker Roles - Fatal编程技术网

C# 确切地说,问题是什么,但是代码现在运行得非常愉快,没有任何修改。不幸的是,由于时间限制,我没有完全调查这个问题。 public override void Run() { Trace.TraceInformation("Foo.PushProces

C# 确切地说,问题是什么,但是代码现在运行得非常愉快,没有任何修改。不幸的是,由于时间限制,我没有完全调查这个问题。 public override void Run() { Trace.TraceInformation("Foo.PushProces,c#,azure,azure-worker-roles,C#,Azure,Azure Worker Roles,确切地说,问题是什么,但是代码现在运行得非常愉快,没有任何修改。不幸的是,由于时间限制,我没有完全调查这个问题。 public override void Run() { Trace.TraceInformation("Foo.PushProcess is running"); try { RunAsync(_cancellationTokenSource.Token).Wait(); // This is where the exceptions po

确切地说,问题是什么,但是代码现在运行得非常愉快,没有任何修改。不幸的是,由于时间限制,我没有完全调查这个问题。
public override void Run()
{
    Trace.TraceInformation("Foo.PushProcess is running");

    try
    {
        RunAsync(_cancellationTokenSource.Token).Wait(); // This is where the exceptions point to
    }
    catch (Exception ex)
    {
        Trace.TraceError("[WORKER] Run error: " + ex);
    }
    finally
    {
        _runCompleteEvent.Set();
    }
}

public override bool OnStart()
{
    // Set the maximum number of concurrent connections
    ServicePointManager.DefaultConnectionLimit = 12;

    // For information on handling configuration changes
    // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

    bool result = base.OnStart();

    _storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
    var queueClient = _storageAccount.CreateCloudQueueClient();
    _pushQueue = queueClient.GetQueueReference("pushes");
    _pushQueue.CreateIfNotExists();

    CreatePushBroker();

    Trace.TraceInformation("Foo.PushProcess has been started");

    return result;
}

private async Task RunAsync(CancellationToken cancellationToken)
{
    while (!cancellationToken.IsCancellationRequested)
    {
        Trace.TraceInformation("Working");
        CloudQueueMessage message = null;
        try
        {
            message = _pushQueue.GetMessage();
            if (message != null)
            {
                ProcessItem(message);
            }
        }
        catch (Exception ex)
        {
            if (message != null && message.DequeueCount > 5)
                _pushQueue.DeleteMessage(message);

            Trace.TraceError("[WORKER] Retrieval Failure: " + ex);
        }

        await Task.Delay(1000, cancellationToken);
    }
}
public override void Run()
{
    Trace.TraceInformation("Foo.PushProcess is running");

    try
    {
        RunAsync(_cancellationTokenSource.Token).Wait(); // This is where the exceptions point to
    }
    catch (Exception ex)
    {
        Trace.TraceError("[WORKER] Run error: " + ex);
    }
    finally
    {
        _runCompleteEvent.Set();
    }
}

public override bool OnStart()
{
    // Set the maximum number of concurrent connections
    ServicePointManager.DefaultConnectionLimit = 12;

    // For information on handling configuration changes
    // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

    bool result = base.OnStart();

    return result;
}

private async Task RunAsync(CancellationToken cancellationToken)
{
    while (!cancellationToken.IsCancellationRequested)
    {
        Trace.TraceInformation("Working");

        // code removed for testing - no work is being done.

        await Task.Delay(1000, cancellationToken);
    }
}
public class WorkerRole : RoleEntryPoint
{
    private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
    private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false);
    private CloudQueue _pushQueue;
    private CloudStorageAccount _storageAccount;

    public override void Run()
    {
        Trace.TraceInformation("WorkerRole1 is running");

        try
        {
            this.RunAsync(this.cancellationTokenSource.Token).Wait();
        }
        catch (Exception ex)
        {
            Trace.TraceError("[WORKER] Run error: " + ex);
        }
        finally
        {
            this.runCompleteEvent.Set();
        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections
        ServicePointManager.DefaultConnectionLimit = 12;

        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
        bool result = base.OnStart();
        _storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
        var queueClient = _storageAccount.CreateCloudQueueClient();
        _pushQueue = queueClient.GetQueueReference("pushes");
        _pushQueue.CreateIfNotExists();

        CreatePushBroker();

        Trace.TraceInformation("Foo.PushProcess has been started");

        return result;

    }

    private void CreatePushBroker()
    {
        return;
    }

    public override void OnStop()
    {
        Trace.TraceInformation("WorkerRole1 is stopping");

        this.cancellationTokenSource.Cancel();
        this.runCompleteEvent.WaitOne();

        base.OnStop();

        Trace.TraceInformation("WorkerRole1 has stopped");
    }

    private async Task RunAsync(CancellationToken cancellationToken)
    {
        // TODO: Replace the following with your own logic.
        while (!cancellationToken.IsCancellationRequested)
        {
            Trace.TraceInformation("Working");
            CloudQueueMessage message = null;
            try
            {
                message = _pushQueue.GetMessage();
                if (message != null)
                {
                    ProcessItem(message);
                }
            }
            catch (Exception ex)
            {
                if (message != null && message.DequeueCount > 5)
                    _pushQueue.DeleteMessage(message);

                Trace.TraceError("[WORKER] Retrieval Failure: " + ex);
            }

            await Task.Delay(1000, cancellationToken);

        }
    }

    private void ProcessItem(CloudQueueMessage message)
    {
        return;
    }
}