Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I'm reading the information from a TCP connection in a thread and after I'm building a JSON message to send it to a REST server.
It takes time to send the message to my application is slow
What's the best way to send the JSON message in a thread ?
I don't know if I can create a new thread each time I send a message...

What I have tried:

C#
private void PluginReceiveClass_OnMessageReceived(Model.Message e)
       {
           foreach (Plugin plugin in loadedPlugins_)
           {
               if (plugin.PluginSendClass != null)
               {
                   if (plugin.IsSendStarted)
                   {
                       plugin.PluginSendClass.SendMessage(e);
                   }
               }
           }
       }
Posted
Updated 19-Feb-16 6:45am
v2

Try using Task :
C#
...
Task.Factory.StartNew( () => plugin.PluginSendClass.SendMessage(e) );
...
 
Share this answer
 
This is another solution in addition to Solution 1.
User ThreadPool as shown below.
C#
ThreadPool.QueueUserWorkItem(o => plugin.PluginSendClass.SendMessage(e));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900