What enabled the increase in the replication service throughput from about 300 to 700 messages per second? How were ConcurrentDictionary and SemaphoreSlim used?
C#
int i = 1; object obj = i; ++i; Console.WriteLine(i); Console.WriteLine(obj); Console.WriteLine((short)obj);
Task: Events are received from users, each needs to be verified in an external source, but it does not respond immediately. Implement VerificationService which: - Accepts events from users - Tries to verify each by contacting an external service - If the response is PENDING, retries sending this event no earlier than 5 seconds later - Maximum 3 attempts, after which the event ID is output to stdout with status FAILED - Successfully processed events are output to stdout with status VERIFIED The templates and stubs of external dependencies are already implemented: 1. VerificationStatus 2. Event 3. VerificationResult 4. IExternalSource public enum VerificationStatus { OK, Pending, Error } public record Event(string Id, string Payload); public record VerificationResult(VerificationStatus Status, string? Message = null); public interface IExternalSource { VerificationResult Verify(string eventId); } public class VerificationService { private readonly IExternalSource _externalSource; private const int MaxAttempts = 3; private static readonly TimeSpan RetryDelay = TimeSpan.FromSeconds(5); public VerificationService(IExternalSource externalSource) { _externalSource = externalSource; } // TODO: implement }
List<Action> actions = new List<Action>(); for (var count = 0; count < 10; count++) { actions.Add(() => System.Console.WriteLine(count)); } foreach (var action in actions) { action(); } What will be in stdout?
What are the values of Sum and Count?
What happens when waiting for the first completed task with Task.WhenAny while other tasks are still running?
How to limit the degree of parallelism when processing a set of asynchronous tasks?
public class A { public virtual void Print1() { System.Console.Write("A"); } public void Print2() { System.Console.Write("A"); } } public class B : A { public override void Print1() { System.Console.Write("B"); } } public class C : B { public new void Print2() { System.Console.Write("C"); } } static void Main(string[] args) { var c = new C(); A a = c; a.Print1(); a.Print2(); c.Print2(); } What will be in stdout?
public struct S : IDisposable { private bool dispose; public void Dispose() { dispose = true; } public bool GetDispose() { return dispose; } } What will be in stdout?
How to organize waiting for new events if the queue is empty, and what is the difference between Channel and ConcurrentQueue?
[name] tell us about an interesting task or solution at your current or previous job that you would like to share.