Click here to Skip to main content
16,006,768 members
Home / Discussions / C#
   

C#

 
AnswerRe: What's better than a static method? Pin
ednrgc1-Dec-06 4:27
ednrgc1-Dec-06 4:27 
QuestionShortkut keys Pin
sujithkumarsl30-Nov-06 22:26
sujithkumarsl30-Nov-06 22:26 
AnswerRe: Shortkut keys Pin
jdkulkarni30-Nov-06 23:15
jdkulkarni30-Nov-06 23:15 
AnswerRe: Shortkut keys Pin
S. Senthil Kumar30-Nov-06 23:20
S. Senthil Kumar30-Nov-06 23:20 
GeneralRe: Shortkut keys Pin
jdkulkarni30-Nov-06 23:48
jdkulkarni30-Nov-06 23:48 
GeneralRe: Shortkut keys Pin
S. Senthil Kumar1-Dec-06 0:24
S. Senthil Kumar1-Dec-06 0:24 
QuestionUsing Excel with ASP.NET Pin
agynr30-Nov-06 22:03
agynr30-Nov-06 22:03 
QuestionGetting error with Chat programe in Server and Client side Pin
M Riaz Bashir30-Nov-06 21:41
M Riaz Bashir30-Nov-06 21:41 
Hi Dear Respected programmers

Kindly help me, I created a little chat server programe. whenever client attemps to send data so errer is arrising from Server side.

Error is : "Cross-thread operation not valid: Control 'textBox2' accessed from a thread other than the thread it was created on."

above mentioned problem is happinig both side. Server side and Client side.

kindly read my following code. and please tell me my mistake.

thank you in advance

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Threading;
using System.IO;

namespace Server
{
public partial class Form1 : Form
{
private Socket connection;
private Thread readThread;
private NetworkStream SocketStream;
private BinaryWriter writer;
private BinaryReader reader;
private int intCounter = 0;
private string strTheReplyer = "";

public Form1()
{
InitializeComponent();


}

public void RunServer()
{

try
{
TcpListener listener = new TcpListener(5252);
listener.Start();

while (true)
{

connection = listener.AcceptSocket();
SocketStream = new NetworkStream(connection);
writer = new BinaryWriter(SocketStream);
reader = new BinaryReader(SocketStream);
textBox2.Text += "\r\nConnection " + intCounter + " received.";
writer.Write("Server=> ok");

//string strTheReplyer = "";

do
{
try
{
strTheReplyer = reader.ReadString();
//message = strTheReplyer.Trim();
//MessageBox.Show(strTheReplyer, "Server");
textBox2.Text = strTheReplyer;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source);
}
}
while (strTheReplyer.ToUpper().Trim() != "CLIENT=> QUIT" && connection.Connected);
textBox2.Text += "\r\nClient gone.";
writer.Close();
reader.Close();
SocketStream.Close();
connection.Close();
++intCounter;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source);
//textBox2.Text += "\r\n" + Convert.ToString(ex.Source) + " " + Convert.ToString(ex.Message);
}
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter && connection != null)
{
writer.Write("Server=> " + textBox1.Text.Trim());
textBox2.Text += "\r\n" + textBox1.Text.Trim();
if (textBox1.Text.ToUpper().Trim() == "QUIT") connection.Close();
}
else
{
//textBox2.Text += "\r\n" + strTheReplyer.Trim();
}
}
catch (Exception ex)
{
textBox2.Text += "\r\n" + ex.Source + ": " + ex.Message;
}
}

private void Form1_Load(object sender, EventArgs e)
{
textBox2.Text += "\r\nWaiting for incoming client ...";
readThread = new Thread(new ThreadStart(RunServer));
readThread.Start();
//textBox2.Text += "\r\n" + message.Trim();
}
}
}
AnswerRe: Getting error with Chat programe in Server and Client side Pin
Christian Graus30-Nov-06 22:26
protectorChristian Graus30-Nov-06 22:26 
AnswerRe: Getting error with Chat programe in Server and Client side Pin
jdkulkarni30-Nov-06 23:09
jdkulkarni30-Nov-06 23:09 
QuestionSMS Website Pin
Ashish Porwal30-Nov-06 20:11
Ashish Porwal30-Nov-06 20:11 
QuestionC# Assembly concept Pin
somagunasekaran30-Nov-06 19:57
somagunasekaran30-Nov-06 19:57 
QuestionCreating a new user Pin
quiteSmart30-Nov-06 19:50
quiteSmart30-Nov-06 19:50 
AnswerRe: Creating a new user Pin
Not Active30-Nov-06 20:07
mentorNot Active30-Nov-06 20:07 
GeneralRe: Creating a new user Pin
quiteSmart30-Nov-06 20:15
quiteSmart30-Nov-06 20:15 
GeneralRe: Creating a new user Pin
Martin#30-Nov-06 21:07
Martin#30-Nov-06 21:07 
GeneralRe: Creating a new user Pin
Eduard Keilholz30-Nov-06 23:46
Eduard Keilholz30-Nov-06 23:46 
GeneralRe: Creating a new user Pin
quiteSmart30-Nov-06 23:58
quiteSmart30-Nov-06 23:58 
AnswerRe: Creating a new user Pin
albCode30-Nov-06 22:41
albCode30-Nov-06 22:41 
GeneralRe: Creating a new user Pin
quiteSmart30-Nov-06 23:59
quiteSmart30-Nov-06 23:59 
GeneralRe: Creating a new user Pin
albCode1-Dec-06 2:22
albCode1-Dec-06 2:22 
JokeRe: Creating a new user Pin
Not Active1-Dec-06 2:36
mentorNot Active1-Dec-06 2:36 
QuestionLoading 500000 rows in to a datatable Pin
chandler8330-Nov-06 17:47
chandler8330-Nov-06 17:47 
AnswerRe: Loading 500000 rows in to a datatable Pin
Not Active30-Nov-06 19:30
mentorNot Active30-Nov-06 19:30 
GeneralRe: Loading 500000 rows in to a datatable Pin
chandler8330-Nov-06 19:35
chandler8330-Nov-06 19:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.