Click here to Skip to main content
15,907,233 members
Home / Discussions / C#
   

C#

 
Questionhow to access methods of Window Service Pin
Sanjib Raj31-Mar-07 19:21
Sanjib Raj31-Mar-07 19:21 
AnswerRe: how to access methods of Window Service Pin
Nader Elshehabi31-Mar-07 22:14
Nader Elshehabi31-Mar-07 22:14 
QuestionTables Pin
Shin-Ra31-Mar-07 10:40
Shin-Ra31-Mar-07 10:40 
QuestionSaving from one txt file into another one problem? Pin
Khoramdin31-Mar-07 8:55
Khoramdin31-Mar-07 8:55 
AnswerRe: Saving from one txt file into another one problem? Pin
darkcalin31-Mar-07 10:04
darkcalin31-Mar-07 10:04 
AnswerRe: Saving from one txt file into another one problem? Pin
Wayne Phipps31-Mar-07 10:25
Wayne Phipps31-Mar-07 10:25 
AnswerRe: Saving from one txt file into another one problem? Pin
Nader Elshehabi31-Mar-07 22:07
Nader Elshehabi31-Mar-07 22:07 
QuestionThe Form freeze ive tryed using threads but... nothing Pin
crazy friend31-Mar-07 8:07
crazy friend31-Mar-07 8:07 
Hi there, ive kind of an issue.... my prob is that im using a TCPListener in a class named Soctek_Server, and i have a form1, so i put a timer on the form in order that the code on the class keep executing, my prob is that only when a client made a request my form1 refresh its content, but until that happend all the form, the visual thing stays in white, all the application stays in a queue... it paralize, what i need to do , is make something with threads, to put the TCP listener in a thread independet of the form that way i could work whit the form.... not mattering if the TCPlistener is active or not. if someone can help me ..... plz

Ive been trying something with threads with the function "pintar" but it doesnt work, the form still paralize when the timer is running....

Here is the code


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Test
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private IContainer components;
private System.Windows.Forms.Button cmdserver;
private System.Windows.Forms.Button cmdclient;
public Socket_Server server;
private System.Windows.Forms.TextBox txtmsg;
private System.Windows.Forms.Label label1;
public Socket_Client client;
private Timer timer1;
System.Threading.Thread myThread;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
server= new Socket_Server();
client = new Socket_Client();
myThread = new System.Threading.Thread(new System.Threading.ThreadStart(pintar));


}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.cmdserver = new System.Windows.Forms.Button();
this.cmdclient = new System.Windows.Forms.Button();
this.txtmsg = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// cmdserver
//
this.cmdserver.Location = new System.Drawing.Point(216, 120);
this.cmdserver.Name = "cmdserver";
this.cmdserver.Size = new System.Drawing.Size(75, 23);
this.cmdserver.TabIndex = 0;
this.cmdserver.Text = "Servidor";
this.cmdserver.Click += new System.EventHandler(this.cmdserver_Click);
//
// cmdclient
//
this.cmdclient.Location = new System.Drawing.Point(216, 176);
this.cmdclient.Name = "cmdclient";
this.cmdclient.Size = new System.Drawing.Size(75, 23);
this.cmdclient.TabIndex = 1;
this.cmdclient.Text = "Cliente";
this.cmdclient.Click += new System.EventHandler(this.cmdclient_Click);
//
// txtmsg
//
this.txtmsg.AcceptsReturn = true;
this.txtmsg.Location = new System.Drawing.Point(216, 84);
this.txtmsg.Name = "txtmsg";
this.txtmsg.Size = new System.Drawing.Size(280, 20);
this.txtmsg.TabIndex = 2;
this.txtmsg.Text = "txtmsg";
this.txtmsg.TextChanged += new System.EventHandler(this.txtmsg_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(216, 248);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 23);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 342);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtmsg);
this.Controls.Add(this.cmdclient);
this.Controls.Add(this.cmdserver);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
//System.Threading.Thread myThread;
//myThread = new System.Threading.Thread(new System.Threading.ThreadStart(Test.Form1.Main));
//myThread.Start();
}

private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
}

private void cmdserver_Click(object sender, System.EventArgs e)
{
label1.Text = "ENTRANDO A SERVER";
server.Begin();
}

private void cmdclient_Click(object sender, System.EventArgs e)
{
myThread.Start();
}

private void txtmsg_TextChanged(object sender, EventArgs e)
{

}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = true;
label1.Text = timer1.Interval.ToString();
server.Begin();

//myThread.Start();


}
public void pintar()
{
label1.Text = "entre al thread";
//myThread.Suspend();
}
}
}



using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Globalization;

namespace Test
{
///
/// Summary description for Socket.
///

///

public class Socket_Server
{
private static Label label;

public Socket_Server()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
IPAddress ipAd = IPAddress.Parse("148.210.182.80");
// use local m/c IP address, and
// use the same in the client

/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,8002);

/* Start Listeneting at the specified port */
myList.Start();

label.Text=label.Text+"/r"+("The server is running at port 8001...");
label.Text=label.Text+"\r"+("The local End point is :" +
myList.LocalEndpoint );
label.Text=label.Text+"\r"+("Waiting for a connection.....");


Socket s=myList.AcceptSocket();
label.Text=label.Text+"\r"+("Connection accepted from " + s.RemoteEndPoint);

byte[] b=new byte[100];
int k=s.Receive(b);
Console.WriteLine("Recieved...");
for (int i=0;i
AnswerRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad31-Mar-07 21:35
Stanciu Vlad31-Mar-07 21:35 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
crazy friend1-Apr-07 19:14
crazy friend1-Apr-07 19:14 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
HexaDeveloper2-Apr-07 12:30
HexaDeveloper2-Apr-07 12:30 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad3-Apr-07 3:33
Stanciu Vlad3-Apr-07 3:33 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
crazy friend6-Apr-07 17:21
crazy friend6-Apr-07 17:21 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad6-Apr-07 23:22
Stanciu Vlad6-Apr-07 23:22 
Questionsteganography implemented in c sharp Pin
dhananjaysonar31-Mar-07 3:56
dhananjaysonar31-Mar-07 3:56 
AnswerRe: steganography implemented in c sharp Pin
Vasudevan Deepak Kumar31-Mar-07 4:25
Vasudevan Deepak Kumar31-Mar-07 4:25 
GeneralRe: steganography implemented in c sharp Pin
dhananjaysonar31-Mar-07 4:45
dhananjaysonar31-Mar-07 4:45 
GeneralRe: steganography implemented in c sharp Pin
Vega0231-Mar-07 6:29
Vega0231-Mar-07 6:29 
GeneralRe: steganography implemented in c sharp Pin
Colin Angus Mackay31-Mar-07 7:17
Colin Angus Mackay31-Mar-07 7:17 
AnswerRe: steganography implemented in c sharp Pin
Stefan Troschuetz31-Mar-07 5:49
Stefan Troschuetz31-Mar-07 5:49 
Questioninvoking a function with string[] Pin
ceken31-Mar-07 3:30
ceken31-Mar-07 3:30 
AnswerRe: invoking a function with string[] Pin
Leslie Sanford31-Mar-07 6:03
Leslie Sanford31-Mar-07 6:03 
GeneralRe: invoking a function with string[] Pin
ceken1-Apr-07 9:46
ceken1-Apr-07 9:46 
GeneralRe: invoking a function with string[] Pin
Leslie Sanford1-Apr-07 11:51
Leslie Sanford1-Apr-07 11:51 
QuestionCalling AddIn functions Pin
swje31-Mar-07 2:55
swje31-Mar-07 2:55 

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.