Note that there are some explanatory texts on larger screens.

plurals
  1. POHubConnection.Start throws error only when called from singleton object
    primarykey
    data
    text
    <p>I have built a notification system with the following code:</p> <pre><code>class SignalRClient { HubConnection hubconn; IHubProxy proxy; public SignalRClient(string url) { hubconn = new HubConnection(url); proxy = hubconn.CreateProxy("XXX.NotificationHub"); hubconn.Start().Wait(); } public void SendMessage() { proxy.Invoke("LiveNotify", new { Application = "SRWinClient", Server = Environment.MachineName, Message = "This is a test", ImgId= 2 }); } } </code></pre> <p>This works great when i trigger it from a test windows forms app (on a button click), but when i call if from a singleton object that i have it fails on the Start().Wait(). I have copy pasted the code and checked a number of times to make sure there were no typos.</p> <p>Here is my notification singleton. It does more than the SignalR bit. it updates Databases and more, but here is the relevant parts:</p> <pre><code>public class CDSNotifier { private static object mLock = new object(); private static CDSNotifier mnotifier = null; private bool enableSignalRNotifications = false; private SignalRNotifier snotifier; private CDSNotifier() { NameValueCollection appSettings = ConfigurationManager.AppSettings; try { enableSignalRNotifications = Convert.ToBoolean(appSettings["EnableSignalRNotifications"]); } catch { }; if (enableSignalRNotifications) { snotifier = new SignalRNotifier(appSettings["SignalRHubURL"]); } } public static CDSNotifier Instance { get { if (mnotifier == null) { // for thread safety, lock an object when lock (mLock) { if (mnotifier == null) { mnotifier = new CDSNotifier(); } } } return mnotifier; } } public void Notify(int applicationId, int? companyId, string message, NotificationType type, string server) { ..... try { if (enableSignalRNotifications) snotifier.SendMessage(applicationId, message, type); } catch { } } </code></pre> <p>Exception that I am getting:</p> <blockquote> <p>System.AggregateException Message: One or more errors occured StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait()</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload