小编lan*_*ess的帖子

从后台线程发送SignalR客户端消息

我正在尝试跟踪文章http://docs.hangfire.io/en/latest/background-processing/tracking-progress.html指导的我的Hangfire后台工作进度

不幸的是,文章中给出的例子不起作用.我在本地下载并运行了示例Web应用程序(https://github.com/HangfireIO/Hangfire.Highlighter).在作业完成后客户订阅时没关系.在这种情况下,消息直接从集线器发送,并已由客户端接收.否则从Hangfire作业调用消息调用,然后没有任何反应.没有例外,没有结果.什么可能导致这种行为?以防万一:hangfire工作无法异步工作......

样本代码:

Hangfire Job(参见Highlight方法)

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using HangFire.Highlighter.Hubs;
using HangFire.Highlighter.Models;
using Microsoft.AspNet.SignalR;

namespace HangFire.Highlighter.Jobs
{
    public class SnippetHighlighter : IDisposable
    {
        private readonly IHubContext _hubContext;
        private readonly HighlighterDbContext _dbContext;

        public SnippetHighlighter()
            : this(GlobalHost.ConnectionManager.GetHubContext<SnippetHub>(), new HighlighterDbContext())
        {
        }

        internal SnippetHighlighter(IHubContext hubContext, HighlighterDbContext dbContext)
        {
            if (hubContext == null) throw new ArgumentNullException("hubContext");
            if (dbContext == null) throw new ArgumentNullException("dbContext");

            _hubContext = hubContext;
            _dbContext = dbContext;
        }

        public void Highlight(int snippetId)
        { …
Run Code Online (Sandbox Code Playgroud)

c# multithreading signalr asp.net-mvc-5 hangfire

7
推荐指数
0
解决办法
3481
查看次数

标签 统计

asp.net-mvc-5 ×1

c# ×1

hangfire ×1

multithreading ×1

signalr ×1