logo
down
shadow

In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?


In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?

By : user3100485
Date : January 12 2021, 07:00 PM
may help you . It's not necessary. This isn't the best example of a channel producer. writer.TryComplete() should be the last call of the try{} block :
code :
private async Task WriteItemsAsync(
    ChannelWriter<int> writer,
    int count,
    int delay,
    CancellationToken cancellationToken)
{
    try
    {
        for (var i = 0; i < count; i++)
        {
            // Check the cancellation token regularly so that the server will stop
            // producing items if the client disconnects.
            cancellationToken.ThrowIfCancellationRequested();
            await writer.WriteAsync(i);

            // Use the cancellationToken in other APIs that accept cancellation
            // tokens so the cancellation can flow down to them.
            await Task.Delay(delay, cancellationToken);
        }
        writer.TryComplete();
    }
    catch (Exception ex)
    {
        writer.TryComplete(ex);
    }   
}
for (var i = 0; i < count; i++)
{
    if (cancellationToken.IsCancellationRequested)
    {
        break;
    }
    await writer.WriteAsync(i);
    await Task.Delay(delay, cancellationToken);
}
writer.TryComplete();
await writer.WriteAsync(i,cancellationToken);


Share : facebook icon twitter icon
Get detailed error for exception in SignalR Core Hub method execution

Get detailed error for exception in SignalR Core Hub method execution


By : Developer30
Date : March 29 2020, 07:55 AM
Any of those help Currently the option to enable detailed errors is not implemented. There is an issue tracking this. My recommendation would be to turn on logging on the server side - the original exception will be logged there.
Call SignalR Core Hub method from Controller

Call SignalR Core Hub method from Controller


By : Borislav Gyorev
Date : March 29 2020, 07:55 AM
With these it helps Solution 1
Another possibility is to inject your HubContext into your controller like:
code :
public VarDesignCommController(IHubContext<VarDesignHub> hubcontext)
{
    HubContext = hubcontext;
    ...
}

private IHubContext<VarDesignHub> HubContext
{ get; set; }
await this.HubContext.Clients.All.InvokeAsync("Completed", id);
public interface ITypedHubClient
{
    Task BroadcastMessage(string name, string message);
}
public class ChatHub : Hub<ITypedHubClient>
{
    public void Send(string name, string message)
    {
        Clients.All.BroadcastMessage(name, message);
    }
}
[Route("api/demo")]
public class DemoController : Controller
{
    IHubContext<ChatHub, ITypedHubClient> _chatHubContext;
    public DemoController(IHubContext<ChatHub, ITypedHubClient> chatHubContext)
    {
        _chatHubContext = chatHubContext;
    }

    // GET: api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        _chatHubContext.Clients.All.BroadcastMessage("test", "test");
        return new string[] { "value1", "value2" };
    }
}
Call Signalr method from Controller .Net Core 2.1

Call Signalr method from Controller .Net Core 2.1


By : user1905781
Date : March 29 2020, 07:55 AM
wish of those help I think you're misunderstanding how it all works together (which is the same thing I did up until yesterday), the hub code is for the client-side script code to call back into and then action, whereas the IHubContext is used as the strongly typed methods that will be sent to the Client-side
Hub
code :
// This class is used by the JavaScript Client to call into the .net core application.
public class ChatHub : Hub<IChatClient>
{

    public static ConcurrentDictionary<string, string> Connections = new ConcurrentDictionary<string, string>();

    // As an example, On connection save the user name with a link to the client Id for later user callback
    public override Task OnConnectedAsync()
    {
        var user = Context.User.Identity.Name;

        Connections.AddOrUpdate(this.Context.ConnectionId, user, (key, oldValue) => user);

        return base.OnConnectedAsync();
    }

    public override Task OnDisconnectedAsync(Exception exception)
    {
        // Do something on disconnect.
    }

    // Add other methods you want to be able to call from JavaScript side in here...
    public void SendMessage(int id, string message)
    {
        // Message doing stuff here.
    }
}
// This provides strongly-typed methods that you'll have on the Client side but these don't exist on the server.
public interface IChatClient
{
    //So this method is a JS one not a .net one and will be called on the client(s)
    Task DoSomething(int id);

    Task NotificationUpdate(int id, string message);
}
public class HomeController : Controller
{
    private readonly IHubContext<ChatHub, IChatClient> _hubContext;

    public HomeController(IHubContext<ChatHub, IChatClient> hubContext)
    {
        _hubContext = hubContext;
    }

    public async Task<ActionResult> Index(int id) 
    {

         // This calls the method on the Client-side
         await _hubContext.Clients.All.DoSomething(id);
    }
}
.Net Core Console App Hostting Signalr Hub Causes GetStreamItemType does not have implementation exception

.Net Core Console App Hostting Signalr Hub Causes GetStreamItemType does not have implementation exception


By : user3251634
Date : March 29 2020, 07:55 AM
With these it helps I gave up while searching the reason and trying to understand GetStreamItemType exception. Finally I created a blank .NET Core Web App and transferred my code from console app into this new app.
SignalR HubConnection.StartAsync exception: GetStreamItemType in Microsoft.AspNetCore.SignalR.Client.Core, v1.1.0.0 does

SignalR HubConnection.StartAsync exception: GetStreamItemType in Microsoft.AspNetCore.SignalR.Client.Core, v1.1.0.0 does


By : shr
Date : January 02 2021, 06:48 AM
may help you . In case anyone else runs into this problem, I'm posting the answer here.
I was able to work around this problem by updating all SignalR and related NUGet packages to their version 3.x pre-release versions.
Related Posts Related Posts :
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org