Eseguire un metodo di una classe in thread da un'altra classe

venerdì 04 settembre 2009 - 12.32

malvin Profilo | Newbie

Ciaooo,
posso chiedere un aiuto?

In pratica, mi servirebbe poter eseguire un TcpSocketServer in una altra classe tramite thread ( non posso instanziare semplicemtne la classe) e poter richiamare in riferimento a questo thread un metodo di TcpSocketServer.

startServer = new Thread(startServerThread2);
startServer.Start();

Dovrei poter usare un metodo SendMessage nella classe dove eseguo il thread..

public void SendMessage(string text) { byte[] byData = System.Text.Encoding.ASCII.GetBytes(text); foreach (TcpClient tcpClient in m_tcpClients) { try { if (tcpClient != null && tcpClient.Client.Connected) tcpClient.GetStream().Write(byData, 0, byData.Length); } catch (IOException) { CloseClient(tcpClient); } } } public void startServerThread2() { Thread.Sleep(250); try { TcpSocketServer x = new TcpSocketServer(); x.StartListening(8000); } catch (Exception ex) { Console.WriteLine(ex); return; } }

Niente form in ballo...

Grazie a tutti voi
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5