public async Task <T> Send <T>(BlendFarmMessage msg, CancellationToken cancel) where T : BlendFarmMessage
        {
            string reqID = Guid.NewGuid().ToString();

            msg.RequestID = reqID;

            BlendFarmMessage response = null;

            SemaphoreSlim sema = new SemaphoreSlim(1);

            //Releases on callback
            _respHandlers.Add(reqID, (resp) =>
            {
                response = resp;
                sema.Release();
            });

            //Consume Initial
            sema.Wait();

            Send(msg);


            TaskCompletionSource <BlendFarmMessage> completionSource = new TaskCompletionSource <BlendFarmMessage>();

            await sema.WaitAsync(cancel);

            sema.Dispose();

            return((T)response);
        }
        /// <summary>
        /// Handle package from client
        /// </summary>
        private void HandlePacket(RenderClient client, BlendFarmMessage p)
        {
            if (p is RenderInfoResponse)
            {
                RenderInfoResponse renderResp = ((RenderInfoResponse)p);

                double progress = Math.Round(((double)renderResp.TilesFinished / renderResp.TilesTotal) * 100, 1);
                if (renderResp.TaskID == CurrentTask)
                {
                    UpdateActivity($"Rendering ({renderResp.TilesFinished}/{renderResp.TilesTotal})", progress);
                }
            }
            if (p is RenderBatchResult)
            {
                RenderBatchResult renderBatchResult = ((RenderBatchResult)p);

                OnBatchResult?.Invoke(this, renderBatchResult);
            }
        }
 public void Send(BlendFarmMessage msg)
 {
     Socket.SendPacket(msg);
 }